JavaScript

#5.1 Timeouts and Dates

김예나 2023. 2. 10. 16:47
  • setTimeout(sayHello, 5000); //5초 후에 함수가 실행됨
const clock = document.querySelector("h2#clock");

function getClock() {
    const date = new Date();
    clock.innerText = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
}

getClock(); //즉시 호출해서 바로 시간을 볼 수 있게
setInterval(getClock, 1000);