File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed
Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Digital Clock</ title >
6+ < style >
7+ body {
8+ background-color : # 0f172a ;
9+ color : # f8fafc ;
10+ font-family : system-ui, Arial;
11+ height : 100vh ;
12+ display : flex;
13+ justify-content : center;
14+ align-items : center;
15+ flex-direction : column;
16+ }
17+ .clock {
18+ font-size : 70px ;
19+ font-weight : bold;
20+ letter-spacing : 2px ;
21+ }
22+ .date {
23+ margin-top : 10px ;
24+ font-size : 20px ;
25+ color : # a5b4fc ;
26+ }
27+ </ style >
28+ </ head >
29+ < body >
30+ < div class ="clock " id ="clock "> 00:00:00</ div >
31+ < div class ="date " id ="date "> --/--/----</ div >
32+
33+ < script >
34+ function updateClock ( ) {
35+ const now = new Date ( ) ;
36+ let hours = now . getHours ( ) ;
37+ let minutes = now . getMinutes ( ) ;
38+ let seconds = now . getSeconds ( ) ;
39+ console . log ( now . getSeconds ( ) )
40+
41+ // // Convert to 12-hour format
42+ // const ampm = hours >= 12 ? "PM" : "AM";
43+ // hours = hours % 12 || 12;
44+
45+ // Add leading zeros
46+ hours = String ( hours ) . padStart ( 2 , "0" ) ;
47+ minutes = String ( minutes ) . padStart ( 2 , "0" ) ;
48+ seconds = String ( seconds ) . padStart ( 2 , "0" ) ;
49+
50+ // Update DOM
51+ document . getElementById ( "clock" ) . textContent = `${ hours } :${ minutes } :${ seconds } ` ;
52+ document . getElementById ( "date" ) . textContent = now . toDateString ( ) ;
53+ }
54+
55+ // Run every second
56+ setInterval ( updateClock , 1000 ) ;
57+
58+ // Run immediately once to avoid 1s delay
59+ updateClock ( ) ;
60+ </ script >
61+ </ body >
62+ </ html >
You can’t perform that action at this time.
0 commit comments