Делаем часы с помощью JavaScript
HTML:
JS:
Шпаргалка с методами объекта Date — ПОСТ
👉 @FrontendPortal | #js
HTML:
<p class="clock"></p>
JS:
const currentTime = () => {
const clock = document.querySelector(".clock");
let date = new Date(),
hh = date.getHours(),
mm = date.getMinutes(),
ss = date.getSeconds();
hh = hh < 10 ? `0${hh}` : hh;
mm = mm < 10 ? `0${mm}` : mm;
ss = ss < 10 ? `0${ss}` : ss;
let time = `${hh}:${mm}:${ss}`;
clock.innerText = time;
};
currentTime();
setInterval(currentTime, 1000);
Шпаргалка с методами объекта Date — ПОСТ
👉 @FrontendPortal | #js