我不确定该怎么做,但我想倒计时到每个星期天。然后在星期一上午12点再次开始倒计时。我正在使用此代码作为我的倒计时,但截至目前我已手动输入倒计时日期。
var end = new Date('15 Feb 2012 06:40:00');
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
var timer;
function showRemaining() {
var now = new Date();
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
alert('Expired');
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
document.getElementById('countdown').innerHTML = 'Days: ' + days + '<br />';
document.getElementById('countdown').innerHTML += 'Hours: ' + hours + '<br />';
document.getElementById('countdown').innerHTML += 'Minutes: ' + minutes + '<br />';
document.getElementById('countdown').innerHTML += 'Seconds: ' + seconds + '<br />';
}
timer = setInterval(showRemaining, 1000);
答案 0 :(得分:2)
你可以随时得到下一个星期天:
var today = new Date();
var sunday = new Date(today.getFullYear(),today.getMonth(),today.getDate()+(7-today.getDay()));