0
안녕하세요 저는 JavaScript를 사용하지 않았으므로 새로운 사용자입니다. 어쩌면 당신은 저를 조금 도와 줄 수 있습니다. 날짜부터 카운트하는 업 카운터를 만들고 싶습니다. 모든 것이 잘 작동하지만 월에 카운터를 추가하고 싶습니다. 날짜의 자바 스크립트에서의 업 카운터
window.onload=function() {
// Month,Day,Year,Hour,Minute,Second
upTime('jan,01,2013,00:00:00'); // ****** Change this line!
};
function upTime(countTo) {
now = new Date();
countTo = new Date(countTo);
difference = (now-countTo);
days=Math.floor(difference/(60*60*1000*24)*1);
years = Math.floor(days/365);
if (years > 1){ days = days - (years * 365)}
hours=Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1);
mins=Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
secs=Math.floor((((difference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
document.getElementById('years').firstChild.nodeValue = years;
document.getElementById('days').firstChild.nodeValue = days;
document.getElementById('hours').firstChild.nodeValue = hours;
document.getElementById('minutes').firstChild.nodeValue = mins;
document.getElementById('seconds').firstChild.nodeValue = secs;
clearTimeout(upTime.to);
upTime.to=setTimeout(function(){ upTime(countTo); },1000);
}
<div id="countup">
It's been
<p id="years">00</p>
<p class="timeRefYears">years</p>
<p id="days">00</p>
<p class="timeRefDays">days</p>
<p id="hours">00</p>
<p class="timeRefHours">hours</p>
<p id="minutes">00</p>
<p class="timeRefMinutes">minutes</p>
<p id="seconds">00</p>
<p class="timeRefSeconds">second</p>
</div>