-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
47 lines (43 loc) · 1.19 KB
/
clock.js
File metadata and controls
47 lines (43 loc) · 1.19 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const time = document.querySelector("#jsClock");
function getTime() {
const clock = new Date();
const year = clock.getFullYear();
const month = String(clock.getMonth() + 1).padStart(2, "0");
const date = String(clock.getDate()).padStart(2, "0");
let day = clock.getDay();
const hour = String(clock.getHours()).padStart(2, "0");
const min = String(clock.getMinutes()).padStart(2, "0");
const sec = String(clock.getSeconds()).padStart(2, "0");
printTime(year, month, date, day, hour, min, sec);
}
function dayConverter(day) {
if (day === 1) {
day = "월";
return day;
} else if (day === 2) {
day = "화";
return day;
} else if (day === 3) {
day = "수";
return day;
} else if (day === 4) {
day = "목";
return day;
} else if (day === 5) {
day = "금";
return day;
} else if (day === 6) {
day = "토";
return day;
} else if (day === 0) {
day = "일";
return day;
}
}
function printTime(year, month, date, day, hour, min, sec) {
time.innerText = `${year}년 ${month}월 ${date}일 ${dayConverter(
day
)}요일 ${hour}:${min}:${sec}`;
}
getTime();
setInterval(getTime, 1000);