[기능]
단순히 현재 시간이 노출되도록 구현했다.
[구현화면]
[index.html]
<!DOCTYPE html>
<head>
<title>바닐라 시계</title>
<style type="text/css">@import url("watch.css");</style>
</head>
<body>
<div>
<p>바닐라 시계</p>
<div class="display_time">
<!--시간 노출-->
<span id="clock">00</span>
</div>
</body>
<script src="watch.js"></script>
</html>
[watch.css]
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR&display=swap');
body {
text-align: center;
font-family: 'Noto Sans KR', sans-serif;
font-size: large;
color: wheat;
background-color:lightslategrey;
}
p {
font-size: 100px;
margin-bottom: 10px;
}
.display_time {
font-size: 120px;
}
[watch.js]
function getClock() {
const date = new Date();
const hour = date.getHours();
const min = date.getMinutes();
const sec = date.getSeconds();
console.log(hour);
const clock = document.getElementById("clock");
clock.innerText = `${hour < 10 ? `0${hour}`:hour}:${min < 10 ? `0${min}`:min}:${sec < 10 ? `0${sec}`:sec}`;
}
function init() {
getClock();
setInterval(getClock, 1000); //1초
}
init();