-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigitalclock.js
More file actions
67 lines (58 loc) · 1.1 KB
/
Copy pathdigitalclock.js
File metadata and controls
67 lines (58 loc) · 1.1 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
clockUpdate = () => {
var days = ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"];
var months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
var a = new Date();
//date
var dayname = days[a.getDay()];
var month = months[a.getMonth()];
var date = a.getDate();
var year = a.getFullYear();
//time
var hr = a.getHours();
var mins = a.getMinutes();
var secs = a.getSeconds();
var am_pm = "AM";
//setting up 12hr format
if (hr == 0) {
hr = 12;
}
if (hr > 12) {
hr = hr - 12;
am_pm = "PM";
}
var ids = [
"day",
"month",
"dayInNum",
"year",
"hours",
"mins",
"secs",
"am_pm",
];
var values = [dayname, month, date, year, hr, mins, secs, am_pm];
//adding padding zeros
for (var j = 4; j <= 6; j++) {
if (values[j] < 10) {
values[j] = "0" + values[j];
}
}
//modifying innerHTML
for (var i = 0; i < values.length; i++) {
document.getElementById(ids[i]).innerHTML = values[i];
}
};
setInterval(clockUpdate, 1000);