File tree 1 file changed +30
-0
lines changed
Source-Code/CountdownTimer
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
2
+ const daysEl = document . getElementById ( 'days' ) ;
3
+ const hoursEl = document . getElementById ( 'hours' ) ;
4
+ const minsEl = document . getElementById ( 'mins' ) ;
5
+ const secondsEl = document . getElementById ( 'seconds' ) ;
6
+
7
+ const eid = '30 Mar 2025' ;
8
+ const formatTime = ( time ) => ( time < 10 ? `0${ time } ` : time ) ;
9
+ const countdown = ( ) => {
10
+ const EidDate = new Date ( eid ) ;
11
+ const currentDate = new Date ( ) ;
12
+
13
+ const totalSeconds = ( EidDate - currentDate ) / 1000 ;
14
+
15
+ const days = Math . floor ( totalSeconds / 3600 / 24 ) ;
16
+ const hours = Math . floor ( totalSeconds / 3600 ) % 24 ;
17
+ const mins = Math . floor ( totalSeconds / 60 ) % 60 ;
18
+ const seconds = Math . floor ( totalSeconds ) % 60 ;
19
+
20
+ daysEl . innerHTML = days ;
21
+ hoursEl . innerHTML = formatTime ( hours ) ;
22
+ minsEl . innerHTML = formatTime ( mins ) ;
23
+ secondsEl . innerHTML = formatTime ( seconds ) ;
24
+ } ;
25
+
26
+ // initial call
27
+ countdown ( ) ;
28
+
29
+ setInterval ( countdown , 1000 ) ;
30
+ } ) ;
You can’t perform that action at this time.
0 commit comments