-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (34 loc) · 827 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const time = document.getElementById("time");
const day = document.getElementById("day");
const midday = document.getElementById("midday");
let clock = setInterval(
function calcTime() {
let date_now = new Date();
let hr = date_now.getHours();
let min = date_now.getMinutes();
let sec = date_now.getSeconds();
let middayValue = "AM";
let days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
day.textContent = days[date_now.getDay()];
middayValue = hr >= 12 ? "PM" : "AM";
if (hr == 0) {
hr = 12;
} else if (hr > 12) {
hr -= 12;
}
hr = hr < 10 ? "0" + hr : hr;
min = min < 10 ? "0" + min : min;
sec = sec < 10 ? "0" + sec : sec;
time.textContent = hr + ":" + min + ":" + sec;
midday.textContent = middayValue;
},
1000
);