-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
71 lines (56 loc) · 1.92 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//ensures DOM is fully loaded before js is used
document.addEventListener("DOMContentLoaded", function () {
function liveTime() {
let now = new Date();
let day_in_words_latest = day(now);
let hours_latest = hoursnow(now);
let second_latest = seconds(now);
let minute_latest = minutes(now);
let month_latest = months(now);
document.querySelector(".hours").innerHTML = hours_latest[0];
document.querySelector(".min").innerHTML = minute_latest;
document.querySelector(".sec").innerHTML = second_latest + " " + hours_latest[1];
document.querySelector(".dayspan").innerHTML = day_in_words_latest;
document.querySelector(".date").innerHTML = now.getDate();
document.querySelector(".month").innerHTML = month_latest;
document.querySelector(".year").innerHTML = now.getFullYear();
}
liveTime(); // Prevents the initial delay
setInterval(liveTime, 1000);
});
function day(now) {
let = day_in_words = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
return day_in_words[now.getDay()];
}
function hoursnow(now) {
let am_pm;
let hours = now.getHours();
if (hours >= 12) {
hours = hours % 12;
am_pm = "pm";
} else {
am_pm = "am";
}
if (hours < 10) {
hours = "0" + hours;
}
return [hours, am_pm];
}
function seconds(now) {
let second = now.getSeconds();
if (second < 10) {
second = "0" + second;
}
return second;
}
function minutes(now) {
let min = now.getMinutes();
if (min < 10) {
min = "0" + min;
}
return min;
}
function months(now) {
let mnth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
return mnth[now.getMonth()]; //get month returns with 0 as January. So, we need to add 1 to get desired result
}