-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
62 lines (56 loc) · 1.47 KB
/
index.html
File metadata and controls
62 lines (56 loc) · 1.47 KB
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
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Digital Clock</title>
<style>
body {
background-color: #0f172a;
color: #f8fafc;
font-family: system-ui, Arial;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.clock {
font-size: 70px;
font-weight: bold;
letter-spacing: 2px;
}
.date {
margin-top: 10px;
font-size: 20px;
color: #a5b4fc;
}
</style>
</head>
<body>
<div class="clock" id="clock">00:00:00</div>
<div class="date" id="date">--/--/----</div>
<script>
function updateClock() {
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
console.log(now.getSeconds())
// // Convert to 12-hour format
// const ampm = hours >= 12 ? "PM" : "AM";
// hours = hours % 12 || 12;
// Add leading zeros
hours = String(hours).padStart(2, "0");
minutes = String(minutes).padStart(2, "0");
seconds = String(seconds).padStart(2, "0");
// Update DOM
document.getElementById("clock").textContent = `${hours}:${minutes}:${seconds}`;
document.getElementById("date").textContent = now.toDateString();
}
// Run every second
setInterval(updateClock, 1000);
// Run immediately once to avoid 1s delay
updateClock();
</script>
</body>
</html>