-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeManage.js
54 lines (45 loc) · 1.39 KB
/
timeManage.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
43
44
45
46
47
48
49
50
51
52
53
54
let hours;
let amOrPm;
let dispHrs;
let dispMin;
let dispSec;
let hours24;
let pageElement;
const timer = () => {
const d = new Date();
hours24 = d.getHours();
hours = d.getHours();
let minutes = d.getMinutes();
let seconds = d.getSeconds();
if (hours >= 12){
hours %= 12;
amOrPm = "PM";
} else {
amOrPm = "AM";
}
dispHrs = hours.toString().padStart(2, "0");
dispMin = minutes.toString().padStart(2, "0");
dispSec = seconds.toString().padStart(2, "0");
document.getElementById("time").innerHTML = `${dispHrs}:${dispMin}:${dispSec} ${amOrPm}`
pageElement = document.getElementById("page1");
if (hours24 < 5){
pageElement.style.backgroundImage = "url('images/night.png')";
pageElement.style.color = "indianred";
} else if (hours24 < 12){
pageElement.style.backgroundImage = "url('images/morning.png')";
pageElement.style.backgroundRepeat = "no-repeat";
pageElement.style.backgroundSize = "cover";
pageElement.style.color = "tomato";
} else if (hours24 < 17){
pageElement.style.backgroundImage = "url('images/noon.png')";
pageElement.style.color = "mintcream";
} else if (hours24 < 19){
pageElement.style.backgroundImage = "url('images/sunset.png')";
pageElement.style.color = "black";
} else {
pageElement.style.backgroundImage = "url('images/night.png')";
pageElement.style.color = "indianred";
}
}
timer();
setInterval(timer, 1000);