Skip to content

Instantly share code, notes, and snippets.

@Ttiki
Created September 30, 2021 19:22
Show Gist options
  • Save Ttiki/906ad2a5ceb8a955d0a1702ecb6aadb6 to your computer and use it in GitHub Desktop.
Save Ttiki/906ad2a5ceb8a955d0a1702ecb6aadb6 to your computer and use it in GitHub Desktop.
Countdown between a date and today's date
//THIS MAY NOT BE THE BEST POSSIBLE WAY TO DO
//THIS CODE IS OLD AND I DIDN'T LOOK INTO IT BEFORE POSTING
//I WILL CHECK AND UPDATE IT IF NECESSARY IN THE FUTURE
//THIS IS JSUT TO TEST GITHUB'S GIST.
// Set the date we're counting down to
var countDownDate = new Date("July 19, 2018 13:15:00").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);
if (hours < 10) {
hours="0"+ hours;
}
if (minutes < 10){
minutes="0"+ minutes;
}
if (seconds < 10){
secondes="0"+ seconds;
}
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = days + " : " + hours + " : "
+ minutes + " : " + seconds;
}, 1000);
@Ttiki
Copy link
Author

Ttiki commented Sep 30, 2021

THIS MAY NOT BE THE BEST POSSIBLE WAY TO DO
THIS CODE IS OLD AND I DIDN'T LOOK INTO IT BEFORE POSTING
I WILL CHECK AND UPDATE IT IF NECESSARY IN THE FUTURE
THIS IS JSUT TO TEST GITHUB'S GIST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment