-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
31 lines (29 loc) · 1 KB
/
clock.js
File metadata and controls
31 lines (29 loc) · 1 KB
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
const calendar = document.querySelector("#calendar");
const dayId = calendar.querySelector("#day");
const monthId = calendar.querySelector("#month");
const dateId = calendar.querySelector("#date");
const yearId = calendar.querySelector("#year");
const clock = document.querySelector("#clock");
function getDate() {
const date = new Date();
const week = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
const day = week[date.getDay()];
const month = date.getMonth() + 1;
const datenum = date.getDate();
const year = date.getFullYear();
dayId.innerText = day;
monthId.innerText = month;
dateId.innerText = datenum;
yearId.innerText = year;
}
function getClock() {
const date = new Date();
const hour = String(date.getHours()).padStart(2, "0");
const minute = String(date.getMinutes()).padStart(2, "0");
const second = String(date.getSeconds()).padStart(2, "0");
clock.innerText = `${hour}:${minute}:${second}`;
}
getClock();
getDate();
setInterval(getDate, 1000);
setInterval(getClock, 1000);