-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
29 lines (25 loc) · 997 Bytes
/
clock.js
File metadata and controls
29 lines (25 loc) · 997 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
const clockContainer = document.querySelector(".clockContainer");
const clock = document.querySelector(".clock");
const hourHand = document.querySelector(`.hour-hand`);
const minHand = document.querySelector(`.min-hand`);
const secondHand = document.querySelector(`.second-hand`);
function getTime() {
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const seconds = date.getSeconds();
clock.innerText = `${hours < 10 ? `0${hours}` : hours}:${
minutes < 10 ? `0${minutes}` : minutes
}:${seconds < 10 ? `0${seconds}` : seconds}`;
const secondDegree = seconds * 6 + 90;
secondHand.style.transform = `rotate(${secondDegree}deg)`;
const minDegree = minutes * 6 + seconds * (6 / 60) + 90;
minHand.style.transform = `rotate(${minDegree}deg)`;
const hourDegree = hours * 30 + minutes * (30 / 60) + 90;
hourHand.style.transform = `rotate(${hourDegree}deg)`;
}
function init() {
getTime();
setInterval(getTime, 1000);
}
init();