1<!DOCTYPE HTML>
2<html>
3<head>
4<meta name="viewport" content="width=device-width, initial-scale=1">
5<style>
6p {
7 text-align: center;
8 font-size: 60px;
9 margin-top: 0px;
10}
11</style>
12</head>
13<body>
14
15<p id="demo"></p>
16
17<script>
18// Set the date we're counting down to
19var countDownDate = new Date("Jan 5, 2021 15:37:25").getTime();
20
21// Update the count down every 1 second
22var x = setInterval(function() {
23
24 // Get today's date and time
25 var now = new Date().getTime();
26
27 // Find the distance between now and the count down date
28 var distance = countDownDate - now;
29
30 // Time calculations for days, hours, minutes and seconds
31 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
32 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
33 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
34 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
35
36 // Output the result in an element with id="demo"
37 document.getElementById("demo").innerHTML = days + "d " + hours + "h "
38 + minutes + "m " + seconds + "s ";
39
40 // If the count down is over, write some text
41 if (distance < 0) {
42 clearInterval(x);
43 document.getElementById("demo").innerHTML = "EXPIRED";
44 }
45}, 1000);
46</script>
47
48</body>
49</html>
50
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <title>Countdown timer using HTML and JavaScript</title>
6 </head>
7 <body>
8 Registration closes in <span id="timer">05:00<span> minutes!
9
10 <!-- custom js -->
11 <script>
12 window.onload = function () {
13 var minute = 5;
14 var sec = 60;
15 setInterval(function () {
16 document.getElementById("timer").innerHTML =
17 minute + " : " + sec;
18 sec--;
19 if (sec == 00) {
20 minute--;
21 sec = 60;
22 if (minute == 0) {
23 minute = 5;
24 }
25 }
26 }, 1000);
27 };
28 </script>
29 </body>
30</html>
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
6var countDownDate = new Date("Jan 5, 2021 15:37:25").getTime();
7
8// Update the count down every 1 second
9var 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>
1function startTimer(duration, display) {
2 var timer = duration, minutes, seconds;
3 setInterval(function () {
4 minutes = parseInt(timer / 60, 10);
5 seconds = parseInt(timer % 60, 10);
6
7 minutes = minutes < 10 ? "0" + minutes : minutes;
8 seconds = seconds < 10 ? "0" + seconds : seconds;
9
10 display.textContent = minutes + ":" + seconds;
11
12 if (--timer < 0) {
13 timer = duration;
14 }
15 }, 1000);
16}
17
18window.onload = function () {
19 var fiveMinutes = 60 * 5,
20 display = document.querySelector('#time');
21 startTimer(fiveMinutes, display);
22};
1<body>
2 <div>Registration closes in <span id="time">05:00</span> minutes!</div>
3</body>