본문 바로가기
develop/javascript

[JS] D-day 만들기

by hyoE 2021. 6. 9.
반응형

D-day 만들기

 

function inIt() {

 

        const nowDate = new Date(); 

        const dDay = new Date('2021-09-30 18:00'); 

        const countDown = dDay - nowDate ;  

        

      

        // 1000ms(1초) * 60(1분) * 60(1시간) * 24(1일) * 365(1년) 

        const countDownday = Math.floor(countDown/(1000*60*60*24));

        const countDownhour = Math.floor((countDown%(1000*60*60*24))/(1000*60*60));

        const countDownMins = Math.floor((countDown%(1000*60*60))/(1000*60));

        const countDownSecs = Math.floor((countDown%(1000*60))/(1000));

 

        const day = document.querySelector('.day');

        const hours = document.querySelector('.hours');

        const mins = document.querySelector('.mins');

        const secs = document.querySelector('.secs');

 

        day.innerText = countDownday;

        hours.innerText = countDownhour;

        mins.innerText = countDownMins;

        secs.innerText = countDownSecs;

}

     

        let start = setInterval(inIt, 1000);

        inIt();

        start;

        

* setInterval(A, B)는 Bms마다 A를 호출, setTimeout은 Bms후 에 A를 '한 번' 호출

  setInterval을 멈출로면 cleaerinterval 사용

반응형

'develop > javascript' 카테고리의 다른 글

[JS] filter  (0) 2021.06.28
[JS] sort  (0) 2021.06.27
[JS] for in / for of 그리고 map / reduce  (0) 2021.06.26
[JS] slice & splic  (0) 2021.06.25
[JS] 2차열 배열  (0) 2021.06.24

댓글