-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
22 lines (19 loc) · 1 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
const $ = (selector) => document.querySelector(selector);
const speed = 15, millInc = 360 / 1000;
$('#year').textContent = new Date().getFullYear();
const runClock = () => {
const ms = new Date().getMilliseconds();
const secs = new Date().getSeconds().toString().padStart(2, '0');
const mins = new Date().getMinutes().toString().padStart(2, '0');
const hours = new Date().getHours();
const hoursStr = (hours).toString().padStart(2, '0');
$('.digital-clock').textContent = `${hoursStr}:${mins}:${secs}:`;
$('.digital-clock-ms').textContent = ms.toString().padStart(3, '0');
const millDegrees = Math.round(Number(ms) * millInc);
const accurateHour = hours + parseFloat(mins / 60) + parseFloat(secs / 3600);
$('.arm.milliseconds').style.transform = `rotate(${millDegrees}deg)`;
$('.arm.seconds').style.transform = `rotate(${6 * secs}deg)`;
$('.arm.minutes').style.transform = `rotate(${6 * mins}deg)`;
$('.arm.hours').style.transform = `rotate(${30 * accurateHour}deg)`;
}
setInterval(runClock, speed);