Javascript

Javascript Clock

HiroDaegu 2021. 8. 26. 00:48
728x90
SMALL
  <h2 id="date"></h2>
  <h2 id="clock">00:00:00</h2>
const clock = document.querySelector("h2#clock");

function getClock() {
  const date = new Date();
  const hours = String(date.getHours()).padStart(2, "0");
  const minutes = String(date.getMinutes()).padStart(2, "0");
  const seconds = String(date.getSeconds()).padStart(2, "0");
  clock.innerText = `${hours}:${minutes}:${seconds}`;
}

getClock();
setInterval(getClock, 1000);
728x90
LIST