-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.js
35 lines (31 loc) · 872 Bytes
/
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
const clockContainer = document.querySelector(".js-clock"),
clockTitle = document.querySelector("h1"),
dateTitle = document.querySelector("h2");
const days = [
"일요일",
"월요일",
"화요일",
"수요일",
"목요일",
"금요일",
"토요일",
];
function getTime() {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const dateDay = date.getDate();
const day = date.getDay();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
clockTitle.innerText = `${hours < 10 ? `0${hours}` : hours}:${
minutes < 10 ? `0${minutes}` : minutes
}:${seconds < 10 ? `0${seconds}` : seconds}`;
dateTitle.innerText = `${year}년 ${month}월 ${dateDay}일 ${days[day]}`;
}
function init() {
getTime();
setInterval(getTime, 1000);
}
init();