-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (29 loc) · 743 Bytes
/
Copy pathapp.js
File metadata and controls
37 lines (29 loc) · 743 Bytes
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
const endDate = "22 May 2024 12:00:00 AM"
document.getElementById("end-date").innerText = endDate;
const inputs = document.querySelectorAll("input")
// const clock = () => {
// }
function clock() {
const end = new Date(endDate)
const now = new Date()
const diff = (end - now) / 1000;
if (diff < 0) return;
// convert into days;
inputs[0].value = Math.floor(diff / 3600 / 24);
inputs[1].value = Math.floor(diff / 3600) % 24;
inputs[2].value = Math.floor(diff / 60) % 60;
inputs[3].value = Math.floor(diff) % 60;
}
// initial call
clock()
/**
* 1 day = 24 hrs
* 1 hr = 60 mins
* 60 min = 3600 sec
*/
setInterval(
() => {
clock()
},
1000
)