-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.js
More file actions
38 lines (33 loc) · 1.24 KB
/
Clock.js
File metadata and controls
38 lines (33 loc) · 1.24 KB
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
function showTime() {
var today = new Date();
// var d = new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var yo;
var days = today.getDate();
var months = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
var year = today.getFullYear();
if(hours <= 9) hours = '0'+ hours;
if(minutes <= 9) minutes = '0'+ minutes;
if(seconds <= 9) seconds = '0'+ seconds;
color = "#"+ hours + minutes + seconds;
document.body.style["background-color"]=color;
document.getElementById("demo").innerHTML = months[today.getMonth()] + "/" + days + "/" + year;
if (hours < 12){
document.querySelector("#clock").innerHTML= hours + ":" + minutes + ":" + seconds + " AM", color;
yo = "Good Morning!";
document.getElementById("yo").innerHTML = yo;
} else if (12 <= hours <= 18) {
document.querySelector("#clock").innerHTML= hours + ":" + minutes + ":" + seconds + " PM", color;
yo = "Good Afternoon";
document.getElementById("yo").innerHTML = yo;
}
else {
document.querySelector("#clock").innerHTML= hours + ":" + minutes + ":" + seconds + " PM", color;
yo = "Good Evening!";
document.getElementById("yo").innerHTML = yo;
}
}
setInterval(showTime, 1000);
showTime();