const now = new Date();
const secnodDeg = (now.getSeconds() / 60) * 360 + 90;
new Date()
현재 시간을 가져온다.
new Date().getSecond()
로 현재 초를 가져온다
이외에 시,분,요일,년도 등 가져올 수 있다.
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Date
// 시침
const hourHand = document.querySelector(".hour-hand");
const hourDeg = (now.getHours() / 12) * 360 + 90;
hourHand.style.transform = `rotate(${hourDeg}deg)`;
element.style
해당 element의 css를 지정할 수 있다.
위는 hour-hand class에 해당하는 element에
transform: rotate(${hourDeg}deg)
를 추가했다.
백틱 기호(`)를 활용해서 js 상수값을 string에 넣어주었다.
setInterval(rotateHands, 1000);
setInterval
을 활용해 callback과 ms(시간)을 지정한다.
ms 마다 callback이 수행된다.