Created
June 18, 2024 17:10
-
-
Save medival/ceab7dd7f19e8d4d30d019041dcbba72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
const second = 1000, | |
minute = second * 60, | |
hour = minute * 60, | |
day = hour * 24; | |
//I'm adding this section so I don't have to keep updating this pen every year :-) | |
//remove this if you don't need it | |
let today = new Date(), | |
dd = String(today.getDate()).padStart(2, "0"), | |
mm = String(today.getMonth() + 1).padStart(2, "0"), | |
yyyy = today.getFullYear(), | |
nextYear = yyyy + 1, | |
dayMonth = "09/30/", | |
birthday = dayMonth + yyyy; | |
today = mm + "/" + dd + "/" + yyyy; | |
if (today > birthday) { | |
birthday = dayMonth + nextYear; | |
} | |
//end | |
const countDown = new Date(birthday).getTime(), | |
x = setInterval(function () { | |
const now = new Date().getTime(), | |
distance = countDown - now; | |
document.getElementById("days").innerText = Math.floor(distance / (day)), | |
document.getElementById("hours").innerText = Math.floor((distance % (day)) / (hour)), | |
document.getElementById("minutes").innerText = Math.floor((distance % (hour)) / (minute)), | |
document.getElementById("seconds").innerText = Math.floor((distance % (minute)) / second); | |
//do something later when date is reached | |
if (distance < 0) { | |
document.getElementById("headline").innerText = "It's my birthday!"; | |
document.getElementById("countdown").style.display = "none"; | |
document.getElementById("content").style.display = "block"; | |
clearInterval(x); | |
} | |
//seconds | |
}, 0) | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment