-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
24 lines (21 loc) · 899 Bytes
/
script.js
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() {
// Get the current time in EST
const now = new Date();
const estTime = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: true // Enables 12-hour format
}).formatToParts(now);
// Extract the time parts
const hours = estTime.find(part => part.type === 'hour').value;
const minutes = estTime.find(part => part.type === 'minute').value;
const seconds = estTime.find(part => part.type === 'second').value;
const ampm = estTime.find(part => part.type === 'dayPeriod').value;
// Update the clock display
document.getElementById('clock').textContent = `${hours}:${minutes}:${seconds} ${ampm.toUpperCase()}`;
}
// Update clock every second
setInterval(updateClock, 1000);
updateClock(); // Initialize clock immediately