-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.js
82 lines (80 loc) · 2.34 KB
/
time.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
72
73
74
75
76
77
78
79
80
81
82
document.addEventListener("DOMContentLoaded", function () {
setInterval(time, 500);
function time() {
const d = new Date();
const title = document.getElementById("title");
const hour = document.getElementById("hour");
const minute = document.getElementById("minute");
const second = document.getElementById("second");
const half = document.getElementById("half");
const day = document.getElementById("day");
const month = document.getElementById("month");
const date = document.getElementById("date");
const year = document.getElementById("year");
const hours = d.getHours();
const minutes = d.getMinutes();
const seconds = d.getSeconds();
const days = d.getDay();
const dates = d.getDate();
const months = d.getMonth() + 1;
const years = d.getFullYear();
if (hours < 10) {
hour.innerHTML = "0" + hours.toString();
} else if (hours >= 13) {
let thing = hours - 12;
if (thing < 10) {
hour.innerHTML = "0" + thing.toString();
} else {
hour.innerHTML = thing.toString();
}
} else {
hour.innerHTML = hours.toString();
}
if (minutes < 1) {
minute.innerHTML = "00";
} else if (minutes < 10) {
minute.innerHTML = "0" + minutes.toString();
} else {
minute.innerHTML = minutes.toString();
}
if (seconds < 1) {
second.innerHTML = "00";
} else if (seconds < 10) {
second.innerHTML = "0" + seconds.toString();
} else {
second.innerHTML = seconds.toString();
}
if (hours < 12) {
half.innerHTML = "am";
} else {
half.innerHTML = "pm";
}
if (days === 0) {
day.innerHTML = "Sunday";
} else if (days === 1) {
day.innerHTML = "Monday";
} else if (days === 2) {
day.innerHTML = "Tuesday";
} else if (days === 3) {
day.innerHTML = "Wednesday";
} else if (days === 4) {
day.innerHTML = "Thursday";
} else if (days === 5) {
day.innerHTML = "Friday";
} else if (days === 6) {
day.innerHTML = "Saturday";
} else {
day.innerHTML = "Sunday";
}
month.innerHTML = months.toString();
date.innerHTML = dates.toString();
year.innerHTML = years.toString();
title.innerHTML =
hour.innerHTML +
":" +
minute.innerHTML +
" " +
half.innerHTML +
" | MacTime";
}
});