/countdown-to-date.html Secret
Created
December 19, 2022 17:05
Star
You must be signed in to star a gist
Simple Countdown to Date/Time
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
<!-- Example setup of HTML for countdown number --> | |
<div><span id="days"></span> Days</div> | |
<div><span id="hours"></span> Hours</div> | |
<div><span id="minutes"></span> Minutes</div> | |
<div><span id="seconds"></span> Seconds</div> |
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 endDate = "10/01/2023"; | |
const second = 1000; | |
const minute = second * 60; | |
const hour = minute * 60; | |
const day = hour * 24; | |
const countDown = new Date(endDate).getTime(), | |
x = setInterval(function () { | |
const now = new Date().getTime(); | |
const 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 | |
)); | |
}, 0); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment