-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (24 loc) · 859 Bytes
/
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
29
30
31
32
33
34
35
36
37
38
const daysEl=document.getElementById('days')
const hrEL=document.getElementById('hr')
const minEl=document.getElementById('min')
const secEl=document.getElementById('sec')
const newYear ='1 jan 2022'
function countdown(){
const newYearDate=new Date(newYear)
const currentDate=new Date()
const totalSeconds=(newYearDate-currentDate)/1000;
const days=Math.floor(totalSeconds/3600/24)
const hrs=Math.floor(totalSeconds/3600)%24
const mins=Math.floor(totalSeconds/60)%60
const seconds=Math.floor(totalSeconds)%60
console.log(days,hrs,mins,seconds)
daysEl.innerHTML=days;
hrEL.innerHTML=formatTime(hrs);
minEl.innerHTML=formatTime(mins);
secEl.innerHTML=formatTime(seconds);
function formatTime(time){
return time<10 ? ('0'+time) : time
}
}
countdown();
setInterval(countdown,1000)