-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (51 loc) · 1.7 KB
/
index.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
const digitalClock = () => {
let myDate = new Date()
let year = myDate.getYear()
// Year starts at 1900
if (year < 1000) {
year += 1900
}
// Get the current days and months based on date
let day = myDate.getDay()
let month = myDate.getMonth()
let currentDate = myDate.getDate()
// Array of days and months
let daysName = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
let monthsName = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
// Get current hours, minutes, and second based on date
let h = myDate.getHours()
let currentHours = myDate.getHours()
let m = myDate.getMinutes()
let s = myDate.getSeconds()
let title = ""
// Function name the hour
if (currentHours >= 6 && currentHours <= 12) {
title = "Good Morning";
} else if (currentHours >= 13 && currentHours <= 17) {
title = "Good Afternoon";
} else if (currentHours >= 18 && currentHours <= 22) {
title = "Good Evening";
} else {
title = "Good Night"
}
// Formating clock
if (h < 10) {
h = "0" + h
}
if (m < 10) {
m = "0" + m
}
if (s < 10) {
s = "0" + s
}
// Display days
document.getElementById("days").innerHTML = `${daysName[day]}`
// Display date
document.getElementsByClassName("date")[0].innerHTML = `${monthsName[month]} ${currentDate} ${year}`
// Display name the hours
document.getElementById("name-the-hours").textContent = title
// Display clock
document.getElementById("clock").innerHTML = `${h}:${m}:${s}`
setInterval("digitalClock()", 1000);
}
digitalClock()