padStart(length, fill) : string 이 가져야 하는 길이.
길이를 채우지 못하면 string의 앞쪽에 0을 추가한다.
padEnd(length, fill) : string이 가져야 하는 길이.
길이를 채우지 못하면 string의 뒤쪽에 0을 추가한다.
app 에서 시간이 흘러가는걸 실시간으로 보여준다.
// clock.js
const clock = document.querySelector("h2#clock");
function updateClock() {
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}`
}
setInterval(() => {
updateClock();
}, 1000);