Difference between revisions of "Widget:Countdown"
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
// I literally just copied this from w3 | // I literally just copied this from w3 | ||
var countDownDate = new Date(<!--{$time}-->).getTime(); | var countDownDate = new Date("<!--{$time}-->").getTime(); | ||
// Update the count down every 1 second | // Update the count down every 1 second |
Revision as of 03:34, 27 January 2019
Jan 1, 0000 00:00:00
<script> // I literally just copied this from w3
var countDownDate = new Date("").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 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("countdown").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
// If the count down is finished, write some text if (distance < 0) { clearInterval(x); document.getElementById("countdown").innerHTML = "EXPIRED"; }
}, 1000); </script>