-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathscript.js
28 lines (22 loc) · 1.05 KB
/
script.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
const days = document.querySelectorAll("days");
const hours = document.querySelectorAll("hours");
const minutes = document.querySelectorAll("minutes");
const seconds = document.querySelectorAll("seconds");
const currentYear = new Date().getFullYear();
const newYearTime = new Date(`January 1 ${currentYear + 1} 00:00:00`);
// Update Countdowntime
function updateCountDownTime() {
const currentTime = new Date();
const diff = newYearTime - currentTime;
// converting time from milliseconds->seconds->minutes->hours->days
const d = Math.floor(diff / 1000 / 60 / 60 / 24);
const h = Math.floor(diff / 1000 / 60 / 60);
const m = Math.floor(diff / 1000 / 60);
const s = Math.floor(diff / 1000);
days.textContent = d;
document.getElementById("days").textContent = d;
document.getElementById("hours").textContent = h < 10 ? "0" + h : h;
document.getElementById("minutes").textContent = m < 10 ? "0" + m : m;
document.getElementById("seconds").textContent = m < 10 ? "0" + s : s;
}
setInterval(updateCountDownTime, 1000);