-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (30 loc) · 1 KB
/
app.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
const endDate = new Date(2022, 0, 5, 19, 0, 0).getTime();
// countdown
let timer = setInterval(function() {
// get today's date
const today = new Date().getTime();
// get the difference
let diff = endDate - today;
let days, hours, minutes, seconds;
if (diff > 0) {
// math
days = Math.floor(diff / (1000 * 60 * 60 * 24));
hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
seconds = Math.floor((diff % (1000 * 60)) / 1000);
}
else {
days = hours = minutes = seconds = 0;
}
// display
document.getElementById("timer").innerHTML =
"<div class=\"days\"> \
<div class=\"numbers\">" + days + "</div>days</div> \
<div class=\"hours\"> \
<div class=\"numbers\">" + hours + "</div>hours</div> \
<div class=\"minutes\"> \
<div class=\"numbers\">" + minutes + "</div>minutes</div> \
<div class=\"seconds\"> \
<div class=\"numbers\">" + seconds + "</div>seconds</div> \
</div>";
}, 1000);