-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.js
31 lines (25 loc) · 922 Bytes
/
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
function currentTime() {
let date = new Date();
let hh = date.getHours();
let mm = date.getMinutes();
// let ss = date.getSeconds();
let day = {0: "sunday", 1: "monday", 2: "tuesday", 3: "wednesday", 4: "thursday", 5: "friday", 6: "saturday"}[date.getDay()]
let session = "AM";
if(hh == 0){
hh = 12;
}
if(hh > 12){
hh = hh - 12;
session = "PM";
}
hh = (hh < 10) ? "0" + hh : hh;
mm = (mm < 10) ? "0" + mm : mm;
// ss = (ss < 10) ? "0" + ss : ss;
// let time = hh + ":" + mm + ":" + ss + " " + session;
document.getElementsByTagName("hh")[0].innerText = hh
document.getElementsByTagName("mm")[0].innerText = mm
document.getElementsByTagName("session")[0].innerText = session
document.getElementsByTagName("day")[0].innerText = day
let t = setTimeout(function(){ currentTime() }, 1000);
}
currentTime();