-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (71 loc) · 1.3 KB
/
script.js
File metadata and controls
80 lines (71 loc) · 1.3 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
72
73
74
75
76
77
78
79
80
function updateClock() {
var now = new Date();
var day_name = now.getDay(),
mo = now.getMonth(),
yyyy = now.getFullYear(),
day_num = now.getDate(),
hh = now.getHours(),
mm = now.getMinutes(),
sec = now.getSeconds(),
amPm = "AM";
// logical statements
if (hh == 0) {
hh = 12;
}
if (hh > 12) {
hh = hh - 12;
amPm = "PM";
}
Number.prototype.pad = function (digits) {
for (var n = this.toString(); n.length < digits; n = 0 + n);
return n;
};
var months = [
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC",
];
var week = [
"SUNDAY",
"MONDAY",
"TUESDAY",
"WEDNESDAY",
"THURSDAY",
"FRIDAY",
"SATURDAY",
];
var ids = [
"dayname",
"month",
"daynum",
"year",
"hour",
"minutes",
"seconds",
];
var values = [
week[day_name],
months[mo],
day_num.pad(2),
yyyy,
hh.pad(2),
mm.pad(2),
sec.pad(2),
amPm,
];
for (var i = 0; i < ids.length; i++)
document.getElementById(ids[i]).firstChild.nodeValue = values[i];
}
function initClock() {
updateClock();
window.setInterval("updateClock()", 1);
}