Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created December 19, 2022 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/41ff730eed5f2bd13aa005fd6736ee33 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/41ff730eed5f2bd13aa005fd6736ee33 to your computer and use it in GitHub Desktop.
Simple Countdown to Date/Time
<!-- 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>
(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