-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (62 loc) · 1.32 KB
/
Copy pathscript.js
File metadata and controls
71 lines (62 loc) · 1.32 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
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
let time = document.getElementById("time");
let date = document.getElementById("date");
let amPm = document.getElementById("ampm");
function updateClock() {
let now = new Date();
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
if (hours === 0) {
hours = 12;
}
if (hours > 12) {
hours = hours - 12;
}
if (now.getHours() < 12) {
amPm.textContent = "AM";
} else {
amPm.textContent = "PM";
}
if (hours < 10) {
hours = `0${hours}`;
}
if (minutes < 10) {
minutes = `0${minutes}`;
}
if (seconds < 10) {
seconds = `0${seconds}`;
}
let timeString = `${hours}:${minutes}:${seconds}`;
time.textContent = timeString;
let dayNumber = now.getDay();
let days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
let dateNumber = now.getDate();
let monthNumber = now.getMonth();
let months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
let year = now.getFullYear();
let dateString = `${days[dayNumber]} • ${dateNumber} ${months[monthNumber]} ${year}`;
date.textContent = dateString;
}
updateClock();
setInterval(updateClock, 1000);