Date()
메인화면 좌측 상단 시계만들때 쓰임
<script>
const clockTitle = document.querySelector("tag");
function getTime(){
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const seconds = date.getSeconds();
const years = date.getFullYear();
const month = date.getMonth();
const monthNames = ["January", "February", "March", "April", "May", "June","July", "August", "September","October", "November", "December"];
clockTitle.innerText = `${years} ${monthNames[month]}\n${
hours > 10 ? hours : `0${hours}`
}:${
minutes > 10 ? minutes : `0${minutes}`
}:${
seconds > 10 ? seconds : `0${seconds}`
}`;
}
function init(){
getTime();
setInterval(getTime,1000);
}
init()
</script>
반응형
'Tistory Web Coding' 카테고리의 다른 글
highlight 추가하기 (0) | 2020.04.10 |
---|
댓글