-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (35 loc) · 1.05 KB
/
index.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
48
49
50
51
52
//const { default: Script } = require("next/script");
let hr = document.querySelector('#hr');
let mn = document.querySelector('#mn');
let sc = document.querySelector('#sc');
setInterval(()=>{
let day = new Date();
let hh = day.getHours() * 30;
let mm = day.getMinutes() * 6;
let ss = day.getSeconds() * 6;
hr.style.transform = `rotateZ(${hh+(mm/12)}deg)`;
mn.style.transform = `rotateZ(${mm}deg)`;
sc.style.transform = `rotateZ(${ss}deg)`;
//Digital clock
let hours=document.getElementById('hour');
let minutes=document.getElementById('minutes');
let seconds=document.getElementById('seconds');
let ampm=document.getElementById('ampm');
let h = new Date().getHours();
let m = new Date().getMinutes();
let s = new Date().getSeconds();
let am=h >= 12 ? "PM" : "AM";
//convert 24hr clock to 12 hr clock
if(h>12)
{
h=h-12;
}
//add zero before single digit
h = (h<10)? "0"+h:h
m = (m<10)? "0"+m:m
s = (s<10)? "0"+s:s
hours.innerHTML=h;
minutes.innerHTML=m;
seconds.innerHTML=s;
ampm.innerHTML=am;
})