-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.html
More file actions
59 lines (57 loc) · 1.92 KB
/
clock.html
File metadata and controls
59 lines (57 loc) · 1.92 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Clock with Date & AM/PM</title>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
background-image: linear-gradient(to right, #a8caba 0%, #5d4157 100%);
color: white;
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
}
#clock {
font-size: 50px;
font-weight: bold;
background: rgba(0, 0, 0, 0.6);
padding: 10px 20px;
border-radius: 10px;
}
#date {
font-size: 30px;
margin-bottom: 10px;
background: rgba(0, 0, 0, 0.6);
padding: 5px 15px;
border-radius: 10px;
}
</style>
</head>
<body>
<div id="date"></div>
<div id="clock"></div>
<script>
function updateClock() {
const now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
let amPm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
document.getElementById('clock').innerText = `${hours}:${minutes}:${seconds} ${amPm}`;
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
document.getElementById('date').innerText = now.toLocaleDateString('en-US', options);
}
setInterval(updateClock, 1000);
updateClock();
</script>
</body>
</html>