setInterval의 첫번째 인수는 내가 실행하고자 하는 함수
두번째 인수는 함수가 호출되는 시간 간격을 의미한다.
const clock = document.querySelector("h2#clock");
function getClock() {
const date = new Date();
console.log(`${date.getHousr()}:${date.getMinutes()}:${date.getSeconds()}`)
}
setInterval(getClock, 1000) // 5초에 한번 실행
String.padStart(맞추는 자릿수, 대체 문자)
const clock = document.querySelector("h2#clock");
function getClock() {
const date = new Date();
const hour = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
const seconds = String(date.getSeconds()).padStart(2, "0");
clock.innerText = `${hour}:${minutes}:${seconds}`;
}
getClock();
setInterval(getClock, 1000); // 5초에 한번 실행