我使用一个脚本计算出一个小时和几秒钟到一个日期,这对于过去的日期是好的,因为它继续计数,但是当日期是在未来时 - 符号附加到前面和我不想要这个,如何防止这种情况被应用
function upTime(countTo) {
now = new Date();
difference = (now-countTo);
days=Math.floor(difference/(60*60*1000*24)*1);
years=Math.floor(days/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('live-hour').innerHTML = hours;
document.getElementById('live-min').innerHTML = mins;
document.getElementById('live-sec').innerHTML = secs;
clearTimeout(upTime.to);
upTime.to=setTimeout(function(){ upTime(countTo); },1000);