-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (34 loc) · 834 Bytes
/
script.js
File metadata and controls
37 lines (34 loc) · 834 Bytes
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
function Clock(options) {
var clock = document.getElementById('clock');
this.start = function start () {
var
date = new Date(),
time = '',
h = date.getHours(),
m = date.getMinutes(),
s = date.getSeconds();
m = (m < 10 ? '0' + m : m);
s = (s < 10 ? '0' + s : s);
if (options.format != 12) {
time = (h < 10 ? '0' + h : h) + ':' + m + ':' + s;
} else {
if (h > 12) {
time = (h - 12) + ':' + m + ':' + s + ' PM';
} else {
time = h + ':' + m + ':' + s + ' AM';
}
}
clock.innerHTML = time;
setTimeout(start, 1000);
};
this.stop = function stop (){
clock.onclick = function () {
alert('Paused! Close to resume.');
}
};
}
var clock = new Clock({
format: '12' // 12 or default 24
});
clock.start();
clock.stop();