-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcountDown.js
More file actions
30 lines (25 loc) · 1.19 KB
/
countDown.js
File metadata and controls
30 lines (25 loc) · 1.19 KB
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
let end = new Date("Sep 28, 2020 00:00:00"); //End Time
let endTime = end.getTime();
document.getElementById("remTime").innerHTML = "Time Remaining until: " + end;
//This function repeats itself after every one second
let cntDwn = setInterval(function () {
let currTime = new Date().getTime(); //Get the current system time
let diff = endTime - currTime;
let days = Math.floor(diff / (1000 * 60 * 60 * 24));
let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((diff % (1000 * 60)) / 1000);
document.getElementById("days").innerHTML = days;
document.getElementById("hours").innerHTML = hours;
document.getElementById("minutes").innerHTML = minutes;
document.getElementById("seconds").innerHTML = seconds;
//After the timer expires
if (diff <= 0) {
clearInterval(cntDwn);
document.getElementById("days").innerHTML = 0;
document.getElementById("hours").innerHTML = 0;
document.getElementById("minutes").innerHTML = 0;
document.getElementById("seconds").innerHTML = 0;
document.getElementById("endMsg").style.visibility = "visible";
}
}, 1000);