-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (33 loc) · 1.18 KB
/
index.js
File metadata and controls
42 lines (33 loc) · 1.18 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
function updateClock(){
var now = new Date();
var dname = now.getDay();
var mo = now.getMonth();
var dnum = now.getDate();
var yr = now.getFullYear();
var hou = now.getHours();
var min = now.getMinutes();
var sec = now.getSeconds();
var pe = "AM" ;
/*setting the hour*/
if(hou==0){
hou = 12;
}
if(hou>12){
hou = hou-12;
pe = "PM";
}
Number.prototype.pad = function(digits){
for (var n = this.toString(); n.length < digits; n = 0 + n);
return n;
}
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var ids = ["dayname","month", "daynumber", "year", "hour", "minute", "seconds", "period"];
var values = [week[dname], months[mo], dnum.pad(2), yr, hou.pad(2), min.pad(2), sec.pad(2), pe];
for(var i = 0; i <ids.length; i++ )
document.getElementById(ids[i]).firstChild.nodeValue = values[i];
}
function initClock(){
updateClock();
window.setInterval("updateClock()", 1);
}