-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
34 lines (27 loc) · 805 Bytes
/
script.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
// Creating Function Clock()
function clock(){
// Var date assignes as function Date()
let date = new Date();
// Assigning values to hh. mm. ss.
let hh = date.getHours();
let mm = date.getMinutes();
let ss = date.getSeconds();
let session = 'AM';
//if hours is 0 the hours will reset
if (hh == 0){
hh = 12;
}
if (hh > 12){
hh -= 12;
session = 'PM'
}
// If hh. mm. or ss. is less than 10 it will add 0 before the number
hh = (hh < 10) ? '0' + hh : hh;
mm = (mm < 10) ? '0' + mm : mm;
ss = (ss < 10) ? '0' + ss : ss;
// The output
let time = hh + ':' + mm + ':' + ss + ' ' + session;
document.getElementById('clock').innerHTML = time;
let t = setTimeout(function(){clock()}, 1000);
}
clock();