-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.js
44 lines (32 loc) · 1.2 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
const deg = 6;
const hour = document.querySelector(".hour");
const min = document.querySelector(".min");
const sec = document.querySelector(".sec");
const setClock = () => {
let day = new Date();
let hh = day.getHours() * 30;
let mm = day.getMinutes() * deg;
let ss = day.getSeconds() * deg;
hour.style.transform = `rotateZ(${hh + mm / 12}deg)`;
min.style.transform = `rotateZ(${mm}deg)`;
sec.style.transform = `rotateZ(${ss}deg)`;
};
setClock();
setInterval(setClock, 1000);
function updateCurrentTime() {
const currentTimeElement = document.getElementById('clockTime');
const currentTime = new Date();
const formattedTime = currentTime.toLocaleTimeString();
currentTimeElement.textContent = formattedTime;
}
setInterval(updateCurrentTime, 1000);
updateCurrentTime();
function updateCurrentDate() {
const currentDateElement = document.getElementById('currentDate');
const currentDate = new Date();
const options = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' };
const formattedDate = currentDate.toLocaleDateString('en-US', options);
currentDateElement.textContent = formattedDate;
}
setInterval(updateCurrentDate, 1000);
updateCurrentDate();