-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (23 loc) · 909 Bytes
/
index.js
File metadata and controls
31 lines (23 loc) · 909 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
25
26
27
28
29
30
31
// DIGITAL CLOCK PROGRAM
// Military time
// function updateClock() {
// const now = new Date();
// const hours = now.getHours().toString().padStart(2, 0);
// const minutes = now.getMinutes().toString().padStart(2, 0);
// const seconds = now.getSeconds().toString().padStart(2, 0);
// const timeString = `${hours}:${minutes}:${seconds}`;
// document.getElementById('clock').textContent = timeString;
// }
function updateClock() {
const now = new Date();
let hours = now.getHours();
const meridiem = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12;
hours = hours.toString().padStart(2, 0);
const minutes = now.getMinutes().toString().padStart(2, 0);
const seconds = now.getSeconds().toString().padStart(2, 0);
const timeString = `${hours}:${minutes}:${seconds} ${meridiem}`;
document.getElementById('clock').textContent = timeString;
}
updateClock();
setInterval(updateClock, 1000);