Skip to content

Instantly share code, notes, and snippets.

@Remiii
Created June 15, 2018 08:56
Show Gist options
  • Save Remiii/edb3c14032a8257973d235b72e092a52 to your computer and use it in GitHub Desktop.
Save Remiii/edb3c14032a8257973d235b72e092a52 to your computer and use it in GitHub Desktop.
Timer
<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 1, 2018 00:00:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an 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="countdown-fintechboost3"
document.getElementById("countdown-fintechboost3").innerHTML = pad2(days) + "DAYS " + pad2(hours) + ":" + pad2(minutes) + ":" + seconds;;
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("countdown-fintechboost3").innerHTML = "EXPIRED";
}
}, 1000);
function pad2(number) {
return (number < 10 ? '0' : '') + number
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment