Skip to content

Instantly share code, notes, and snippets.

@diki-haryadi
Last active August 30, 2021 04:02
Show Gist options
  • Select an option

  • Save diki-haryadi/6459df14a160c9c3a6054cdc3afbebae to your computer and use it in GitHub Desktop.

Select an option

Save diki-haryadi/6459df14a160c9c3a6054cdc3afbebae to your computer and use it in GitHub Desktop.
Coundown 1 minutes
<!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>
<p id="demo"></p>
<script>
// Set the date we're counting down to
var countDownDate = new Date();
countDownDate2 = new Date ( countDownDate );
countDownDate2.setMinutes ( countDownDate.getMinutes() + 30 );
countDownDate2.getTime()
//var countDownDate = new Date("Jan 5, 2022 15:37:25").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 = countDownDate2 - now;
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = minutes + "m " + seconds + "s " ;
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment