-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.57 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function main() {
const second = 1000;
const minute = second * 60;
const hour = minute * 60;
const day = hour * 24;
//I'm adding this section so I don't have to keep updating this pen every year :-)
//remove this if you don't need it
let today = new Date();
let dd = String(today.getDate()).padStart(2, "0");
let mm = String(today.getMonth() + 1).padStart(2, "0");
let yyyy = today.getFullYear();
let dayMonth = "04/13/";
let eventTime = "April 13, 2024 11:00:00 GMT+0530";
today = `${mm}/${dd}/${yyyy}`;
//end
const countDown = new Date(eventTime).getTime();
const x = setInterval(() => {
const now = new Date().getTime();
const distance = countDown - now;
const days = String(Math.floor(distance / day)).padStart(2, "0");
const hours = String(Math.floor((distance % day) / hour)).padStart(
2,
"0"
);
const minutes = String(Math.floor((distance % hour) / minute)).padStart(
2,
"0"
);
const seconds = String(
Math.floor((distance % minute) / second)
).padStart(2, "0");
// DO below only if that element exists
if (document.getElementById("days")) {
document.getElementById("days").innerText = days;
document.getElementById("hours").innerText = hours;
document.getElementById("minutes").innerText = minutes;
document.getElementById("seconds").innerText = seconds;
} else {
document.getElementById("days1").innerText = days;
document.getElementById("hours1").innerText = hours;
document.getElementById("minutes1").innerText = minutes;
document.getElementById("seconds1").innerText = seconds;
}
//seconds
}, 0);
}
main()