-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscript.js
66 lines (48 loc) · 1.64 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const HOURHAND = document.querySelector("#hour");
const MINUTEHAND = document.querySelector("#minute");
const SECONDHAND = document.querySelector("#second");
var date = new Date();
// console.log(date);
let hr = date.getHours();
let min = date.getMinutes();
let sec = date.getSeconds();
// console.log("Hour: " + hr + " Minute: " + min + " Second: " + sec);
let hrPosition = (hr*360/12)+(min*(360/60)/12);
let minPosition = (min*360/60)+(sec*(360/60)/60);
let secPosition = sec*360/60;
function runTheclock(){
hrPosition = hrPosition + (3/360);
minPosition = minPosition + (6/60);
secPosition = secPosition + 6;
HOURHAND.style.transform = "rotate(" + hrPosition + "deg)";
MINUTEHAND.style.transform = "rotate(" + minPosition + "deg)";
SECONDHAND.style.transform = "rotate(" + secPosition + "deg)";
}
var interval = setInterval(runTheclock,1000);
/*Digital clock part*/
function showTime(){
var date = new Date();
var hr = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
var session = "AM";
if(hr == 0){
hr = 12;
}
if(hr > 12){
hr = hr - 12;
session = "PM";
}
hr = (hr < 10) ? "0" + hr : hr;
min = (min < 10) ? "0" + min : min;
sec = (sec < 10) ? "0" + sec : sec;
var time = hr + ":" + min + ":" + sec + " " + session;
document.getElementById("digitalClock").innerText = time;
document.getElementById("digitalClock").textContent = time;
document.getElementById("date").innerText = date;
document.getElementById("date").textContent = date;
setTimeout(showTime,1000);
};
showTime();
/*Digital clock part*/
// setClock();