Skip to content

Instantly share code, notes, and snippets.

@thecodepoetry
Created May 7, 2024 04:29
Show Gist options
  • Save thecodepoetry/a2d9a5be7a5be70c321729956d0e8070 to your computer and use it in GitHub Desktop.
Save thecodepoetry/a2d9a5be7a5be70c321729956d0e8070 to your computer and use it in GitHub Desktop.
RS countdown
var countDownDate = new Date("july 01, 2024 15:37:25").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById("c_days").innerHTML = days;
document.getElementById("c_hours").innerHTML = hours;
document.getElementById("c_minutes").innerHTML = minutes;
document.getElementById("c_seconds").innerHTML = seconds;
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment