-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.js
48 lines (36 loc) · 1.15 KB
/
clock.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
months_names = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
days_names = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
function startTime() {
var today = new Date();
h = today.getHours();
m = today.getMinutes();
s = today.getSeconds();
document.getElementById('clock').innerHTML = h + ':' + leadingZero(m);
setTimeout(startTime,(60-s)*1000);
}
function startDate() {
var today = new Date();
y = today.getFullYear();
m = months_names[today.getMonth()];
d = today.getDate();
document.getElementById('date').innerHTML = y + ". " + m + " " + d + ".";
document.getElementById('day').innerHTML = days_names[today.getDay()];
setTimeout(startDate,msecUntilMidnight(today));
}
function startDateTime() {
startTime();
startDate();
}
function leadingZero(a) {
if (a < 10)
return '0' + a;
return a;
}
function msecUntilMidnight(today) {
var midnight = new Date();
midnight.setHours( 24 );
midnight.setMinutes( 0 );
midnight.setSeconds( 0 );
midnight.setMilliseconds( 0 );
return midnight.getTime() - today.getTime();
}