// 현재 시간 출력
- Date 객체를 이용해 현재 시간을 출력
const today = new Date();
today.getHours()
today.getMinutes()
today.getSeconds()
// 1초마다 갱신
setInterval(함수명, 1000);
- html
<div class="date-wrap">
<div class="js"></div>
<div class="date">
<p class="date-tit">digital clock</p>
<div class="now">
<div class="time hour">00</div>
<div class="divider">:</div>
<div class="time min">00</div>
<div class="divider">:</div>
<div class="time sec">00</div>
</div>
<div class="date-desc">
html, css & javascript
</div>
</div>
</div>
- css
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.date-wrap {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
background: #000;
}
.js {
position: absolute;
top: 0;
left: 0;
width: 240px;
height: 240px;
background: #F7DF1D;
}
.js:after {
position: absolute;
right: 20px;
bottom: 0;
content: 'JS';
font-size: 120px;
font-weight: bold;
}
.date {
display: flex;
width: 100%;
height: 100%;
flex-flow: column;
justify-content: space-evenly;
align-items: center;
color: #fff;
text-align: center;
}
.now {
display: flex;
justify-content: center;
align-items: center;
column-gap: 30px;
font-family: Rajdhani;
font-size: 100px;
}
.time {
width: 150px;
font-weight: bold;
letter-spacing: 8px;
text-align: center;
text-shadow: 0px 0px 60px mediumturquoise;
}
.date-tit {
text-transform: uppercase;
font-family: Permanent Marker;
font-size: 65px;
color: #B5115A;
}
.date-desc {
text-transform: uppercase;
font-size: 30px;
font-weight: bold;
letter-spacing: 5px;
color: #fff;
opacity: .6;
width: 100%;
margin-top: 70px;
}
- js
<script>
// const date = document.querySelector('.date h1');
const hour = document.querySelector('.hour');
const min = document.querySelector('.min');
const sec = document.querySelector('.sec');
function clock() {
const now = new Date();
hour.innerText = now.getHours();
min.innerText = now.getMinutes();
sec.innerText = now.getSeconds();
}
setInterval(clock, 1000);
</script>
'Web > Java Script' 카테고리의 다른 글
[제이쿼리] if조건문을 이용한 스크롤 후 헤더 디자인 변경 (0) | 2022.02.15 |
---|---|
[제이쿼리] 반응형 모달(translate속성 : 애니메이션 효과) (0) | 2022.02.09 |
[js 독학백서] 따라하는 걸음마 문제 #1 할 일 등록하기 (TodoList) (0) | 2022.01.12 |
[js 독학백서] 5. 객체 심화 (0) | 2021.12.30 |
[js 독학백서] 4. 배열 심화 (0) | 2021.12.30 |