День добрый.
Есть такой код
$(document).ready(function () {
function CountdownTimer(elm, tl, mes) {
this.initialize.apply(this, arguments);
}
CountdownTimer.prototype = {
initialize: function (elm, tl, mes) {
this.elem = document.getElementById(elm);
this.tl = tl;
this.mes = mes;
},
countDown: function () {
var timer = '';
// var today=new Date();
var today = (new Date()).getTime() + 60 * 1000;
var day = Math.floor((this.tl - today) / (24 * 60 * 60 * 1000));
var hour = Math.floor(((this.tl - today) % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
var min = Math.floor(((this.tl - today) % (24 * 60 * 60 * 1000)) / (60 * 1000)) % 60;
var sec = Math.floor(((this.tl - today) % (24 * 60 * 60 * 1000)) / 1000) % 60 % 60;
var me = this;
if ((this.tl - today) > 0) {
timer += '<span class="number-wrapper"><div class="line"></div><div class="caption">Дни</div><span class="number day">' + day + '</span></span>';
timer += '<span class="number-wrapper"><div class="line"></div><div class="caption">Часы</div><span class="number hour">' + hour + '</span></span>';
timer += '<span class="number-wrapper"><div class="line"></div><div class="caption">Минуты</div><span class="number min">' + this.addZero(min) + '</span></span><span class="number-wrapper"><div class="line"></div><div class="caption">Секунды</div><span class="number sec">' + this.addZero(sec) + '</span></span>';
this.elem.innerHTML = timer;
tid = setTimeout(function () {
me.countDown();
}, 10);
} else {
this.elem.innerHTML = this.mes;
return;
}
},
addZero: function (num) {
return ('0' + num).slice(-2);
}
}
function CDT() {
// Set countdown limit
var tl = new Date();
alert(tl);
// You can add time's up message here
var timer = new CountdownTimer('CDT', tl, '<span class="number-wrapper"><div class="line"></div><span class="number end">Время истекло</span></span>');
timer.countDown();
}
function CDT2() {
// Set countdown limit
var tl = new Date('2014/03/30 00:00:00');
// You can add time's up message here
var timer = new CountdownTimer('CDT2', tl, '<span class="number-wrapper"><div class="line"></div><span class="number end">Время истекло</span></span>');
timer.countDown();
}
window.onload = function () {
CDT();
CDT2();
}
function CountdownTimer(elm, tl, mes) {
this.initialize.apply(this, arguments);
}
});
Подскажите пожалуйста как сделать так, чтобы он считал оставшееся время до конца суток? Т.е. каждый день бы обнулялся и начинал сначала 24 часа отсчитывать?