Guest User

Untitled

a guest
May 27th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <!-- Display the countdown timer in an element -->
  2. <p id="demo"></p>
  3.  
  4. <script>
  5. // Set the date we're counting down to
  6. var countDownDate = new Date("May 18, 2020 07:22:20").getTime();
  7.  
  8. // Update the count down every 1 second
  9. var x = setInterval(function() {
  10.  
  11. // Get today's date and time
  12. var now = new Date().getTime();
  13.  
  14. // Find the distance between now and the count down date
  15. var distance = countDownDate - now;
  16.  
  17. // Time calculations for days, hours, minutes and seconds
  18. var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  19. var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  20. var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  21. var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  22.  
  23. // Display the result in the element with id="demo"
  24. document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  25. + minutes + "m " + seconds + "s ";
  26.  
  27. // If the count down is finished, write some text
  28. if (distance < 0) {
  29. clearInterval(x);
  30. document.getElementById("demo").innerHTML = "EXPIRED";
  31. }
  32. }, 1000);
  33. </script>
Advertisement
Add Comment
Please, Sign In to add comment