-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (18 loc) · 829 Bytes
/
script.js
File metadata and controls
24 lines (18 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function updateClock() {
const currentTime = new Date();
const hours = currentTime.getHours();
const minutes = currentTime.getMinutes();
const seconds = currentTime.getSeconds();
const ampm = hours >= 12 ? 'PM' : 'AM';
const formattedHours = hours % 12 || 12;
const formattedMinutes = minutes < 10 ? '0' + minutes : minutes;
const formattedSeconds = seconds < 10 ? '0' + seconds : seconds;
const formattedTime = `${formattedHours}:${formattedMinutes}:${formattedSeconds} ${ampm}`;
// Get the clock element and set its text content
const clockElement = document.getElementById('clock');
clockElement.textContent = formattedTime;
}
// Set up the interval for updating the clock
setInterval(updateClock, 1000);
// Initial call to updateClock
updateClock();