-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (23 loc) · 870 Bytes
/
script.js
File metadata and controls
31 lines (23 loc) · 870 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
let days1 = document.getElementById("d");
let hours1 = document.getElementById("hr");
let mins1 = document.getElementById("min");
let sec1 = document.getElementById("sec");
const newYears = "2023-09-06"; //You can change the date
function countdown() {
const newYearsDate = new Date(newYears);
const currentDate = new Date();
const totalSeconds = (newYearsDate - currentDate) / 1000;
const days = Math.floor(totalSeconds / 3600 / 24);
const hours = Math.floor(totalSeconds / 3600) % 24;
const minutes = Math.floor(totalSeconds / 60) % 60;
const seconds = Math.floor(totalSeconds) % 60;
days1.innerHTML = days;
hours1.innerHTML = formatTime(hours);
mins1.innerHTML = formatTime(minutes);
sec1.innerHTML = formatTime(seconds);
}
function formatTime(time) {
return time < 10 ? `0${time}` : time;
}
countdown();
setInterval(countdown, 1000);