Created
July 6, 2022 19:54
-
-
Save dandyraka/f13ee01ab304d7b6448309dcd1d082c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
p { | |
text-align: center; | |
font-size: 60px; | |
margin-top: 0px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="hours"></div> | |
<div id="minutes"></div> | |
<div id="seconds"></div> | |
<script> | |
var countDownDate = new Date("Jul 08, 2022 12:00:00 GMT+7").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 hours, minutes and seconds | |
var hours = 0; | |
var minutes = 0; | |
var seconds = 0; | |
while (true) | |
if (distance >= (1000*60*60)) { | |
hours++; | |
distance -= (1000*60*60); | |
} else | |
if (distance >= (1000*60)) { | |
minutes++; | |
distance -= (1000*60); | |
} else | |
if (distance >= 1000) { | |
seconds++; | |
distance -= 1000; | |
} else | |
break; | |
// Format output-string | |
var hours = (hours < 10 ? '0' + hours : hours); | |
minutes = (minutes < 10 ? '0' + minutes : minutes); | |
seconds = (seconds < 10 ? '0' + seconds : seconds); | |
// Display the result in the element with id="demo" | |
if (distance > 0) { | |
document.getElementById("hours").innerHTML = hours; | |
document.getElementById("minutes").innerHTML = minutes; | |
document.getElementById("seconds").innerHTML = seconds; | |
} else | |
document.getElementById("hours").innerHTML = "EXPIRED"; | |
}, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment