const XMASDAY = new Date("2020-12-24:00:00:00+0900");
function getTargetDay() {
const xmas = document.getElementById("xmasDay");
const year = XMASDAY.getFullYear();
const month = XMASDAY.getMonth() + 1;
const date = XMASDAY.getDate() + 1;
const hours = XMASDAY.getHours();
const minutes = XMASDAY.getMinutes();
const seconds = XMASDAY.getSeconds();
// 자리수 맞추는 것 재밌다 ! 엑셀을 할 때도 자리수 맞추는 것 매우 중요하게 여겼기 때문에 ~
xmas.innerText = `${year}년 ${month}월 ${date}일 ${
hours < 10 ? `0${hours}` : hours
}시 ${minutes < 10 ? `0${minutes}` : minutes}분 ${
seconds < 10 ? `0${seconds}` : seconds
}초`;
}
function getCurrentTime() {
const nowTime = new Date();
const currentTime = document.getElementById("currentTime");
const year = nowTime.getFullYear();
const month = nowTime.getMonth() + 1;
const date = nowTime.getDate();
const hours = nowTime.getHours();
const minutes = nowTime.getMinutes();
const seconds = nowTime.getSeconds();
currentTime.innerText = `${year}년 ${month}월 ${date}일 ${
hours < 10 ? `0${hours}` : hours
}시 ${minutes < 10 ? `0${minutes}` : minutes}분 ${
seconds < 10 ? `0${seconds}` : seconds
}초`;
}
function getGapTime(){
let Targetday = new Date("2020-12-24:00:00:00+0900").getTime();
let now = new Date().getTime();
let gap = Targetday - now;
console.log(gap)
let date = Math.floor(gap / (1000 * 60 * 60 * 24));
let hours = Math.floor((gap % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((gap % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((gap % (1000 * 60)) / 1000);
document.getElementById("gapTime").innerHTML = `${date} day ${
hours < 10 ? `0${hours}` : hours
} hour ${minutes < 10 ? `0${minutes}` : minutes} min ${
seconds < 10 ? `0${seconds}` : seconds
} sec`;
}
// 시차때문에 이걸 쓰라고 했는데 사용하지않았다. 어떻게 썼어야 했는가...?
const NINE_HOURS_MILLISECONDS = 32400000;
function init() {
getTargetDay();
getCurrentTime();
setInterval(getCurrentTime, 1000);
setInterval(getGapTime, 1000);
}
init();
댓글남기기