-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.html
52 lines (43 loc) · 1.31 KB
/
clock.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Clock</title>
<style>
/* Add your CSS styles here */
body {
font-family: Arial, sans-serif;
text-align: center;
padding-top: 100px;
}
#clock {
font-size: 48px;
}
</style>
</head>
<body>
<div id="clock"></div>
<script>
// JavaScript to update the clock
function updateClock() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
// Pad single digit numbers with a leading zero
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
// Format the time as HH:MM:SS
var time = hours + ':' + minutes + ':' + seconds;
// Update the clock display
document.getElementById('clock').innerText = time;
}
// Call updateClock every second
setInterval(updateClock, 1000);
// Initial call to display the clock immediately
updateClock();
</script>
</body>
</html>