작업 소스들

디데이 스크립트

June 2022. 12. 5. 02:41

js

js 파일로 만들어서 html에 불러오기

const remainTime = document.querySelector("#remain-time");

function diffDay() {
    const masTime = new Date(); //시작일
    const todayTime = new Date("2022-12-01"); // 오늘
    
    const diff = masTime - todayTime;

    const diffDay = String(Math.floor(diff / (1000*60*60*24)));
    const diffHour =String( Math.floor((diff / (1000*60*60)) % 24)).padStart(2,"0");
    const diffMin = String(Math.floor((diff / (1000*60)) % 60)).padStart(2,"0");
    const diffSec = String(Math.floor(diff / 1000 % 60)).padStart(2,"0");
    
    remainTime.innerText = `${diffDay}`;
}

diffDay();
setInterval(diffDay, 1000);

 

html

<span id="remain-time"></span>Days
<script src="./dday.js"></script>