我有一个倒计时jquery工作小时,分钟和秒。到目前为止,这完美地运作。不过我想要它也算上一天
HTML
<div id="counttime">24:00:00</div>
<div id="cons"></div>
JQUERY
function pad(num) {
return num<10?"0"+num:num;
}
$(function() {
var tCont = $('#counttime');
var timer = tCont.html().split(':');
if (timer.length === 2) timer.unshift(0);
var endMilli= timer[0]*60*60*1000;
endMilli += timer[1]*60*1000
endMilli += timer[2]*1000;
if(endMilli > 0) {
var endTime = new Date(Date.now()+endMilli);
$("#cons").append("<br>"+endTime);
var tId = setInterval(function() {
var diff = endTime.getTime()-Date.now();
if (diff<=0) {
tCont.html("00:00:00");
clearInterval(tId);
}
else {
var d = new Date(diff);
hh = pad(d.getUTCHours());
mm = pad(d.getMinutes());
ss = pad(d.getSeconds());
tCont.html(""+hh+":"+mm+":"+ss);
}
},300);
}
});
答案 0 :(得分:1)
答案 1 :(得分:0)
您的hh
部分应该乘以天数!
hh = pad(d.getUTCHours() + d.getDay()*24);
您还应该添加月份......不确定这是否容易。 或者你可以试试这个:
var hours = Math.abs(date1 - date2) / 36e5;
hh = pad(hours);
36e5 = 60*60*1000
毫秒