-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (32 loc) · 1.03 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
const day = document.querySelector(".day .numb");
const hour = document.querySelector(".hour .numb");
const min = document.querySelector(".min .numb");
const sec = document.querySelector(".sec .numb");
var timer = setInterval(() => {
var currentDate = new Date().getTime();
var launchDate = new Date("Sep 18, 2020 13:00:00").getTime();
var duration = launchDate - currentDate;
var days = Math.floor(duration / (1000 * 60 * 60 * 24));
var hours = Math.floor((duration % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((duration % (1000 * 60)) / 1000);
day.innerHTML = days;
hour.innerHTML = hours;
min.innerHTML = minutes;
sec.innerHTML = seconds;
if (days < 10) {
day.innerHTML = "0" + days;
}
if (hours < 10) {
hour.innerHTML = "0" + hours;
}
if (minutes < 10) {
min.innerHTML = "0" + minutes;
}
if (seconds < 10) {
sec.innerHTML = "0" + seconds;
}
if (duration < 0) {
clearInterval(timer);
}
}, 1000);