-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (24 loc) · 1.25 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(function () {
const second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;
// Set your target date and time here
let targetDate = new Date("06/08/2024 10:02:00"); // Format: MM/DD/YYYY HH:MM:SS
const countDown = targetDate.getTime(),
x = setInterval(function() {
const now = new Date().getTime(),
distance = countDown - now;
document.getElementById("days").innerText = Math.floor(distance / (day)),
document.getElementById("hours").innerText = Math.floor((distance % (day)) / (hour)),
document.getElementById("minutes").innerText = Math.floor((distance % (hour)) / (minute)),
document.getElementById("seconds").innerText = Math.floor((distance % (minute)) / second);
// Do something when the target date is reached
if (distance < 0) {
document.getElementById("headline").innerText = "The countdown has ended!";
document.getElementById("countdown").style.display = "none";
document.getElementById("content").style.display = "block";
clearInterval(x);
}
}, 1000); // Update every second
})();