-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
34 lines (32 loc) · 1.03 KB
/
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
25
26
27
28
29
30
31
32
33
34
const hourSpan = document.querySelector('.hours');
const minuteSpan = document.querySelector('.minutes');
const secondSpan = document.querySelector('.seconds');
const time = document.querySelector('.time');
const d = new Date();
let seconds = d.getSeconds();
let minutes = d.getMinutes();
let hours = d.getHours();
if (hours > 12) {
hours = hours - 12;
time.innerText = "PM";
} else {
time.innerText = "AM";
}
hourSpan.innerText = String(hours).padStart(2, '0');
minuteSpan.innerText = String(minutes).padStart(2, '0');
secondSpan.innerText = String(seconds).padStart(2, '0');
setInterval(function () {
const d = new Date();
let seconds = d.getSeconds();
let minutes = d.getMinutes();
let hours = d.getHours();
if (hours > 12) {
hours = hours - 12;
time.innerText = "PM";
} else {
time.innerText = "AM";
}
hourSpan.innerText = String(hours).padStart(2, '0');
minuteSpan.innerText = String(minutes).padStart(2, '0');
secondSpan.innerText = String(seconds).padStart(2, '0');
}, 500);