我尝试在我的网站上制作计时器。
现在我已经用“结束日”减去“今日”这样: -
var end = new Date( 2014 , 08 , 16 , 14 , 20 , 0 );
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);
document.getElementById('d').innerHTML = '-';
document.getElementById('m').innerHTML = '-';
document.getElementById('h').innerHTML = '-';
document.getElementById('s').innerHTML = '-';
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);
if(days)
{
document.getElementById('d').innerHTML = days;
$("#d").parent('li').show();
}
document.getElementById('h').innerHTML = hours;
document.getElementById('m').innerHTML = minutes;
document.getElementById('s').innerHTML = seconds;
$(".timers").css({'visibility':'visible'});
}
timer = setInterval(showRemaining, 1000);
此操作的结果必须是1天,但它显示我31天!!
我尝试提醒
var end = new Date( 2014 , 08 , 16 , 14 , 20 , 0 );
它告诉我Tue sep 16 2014 14:20:00 GMT +0300 (Jerusalem Daylight Time)
错误,必须与Tue Agu 16 2014 14:20:00 GMT +0300 (Jerusalem Daylight Time)
为什么!!
答案 0 :(得分:6)
因为在JavaScript中,月份从0
开始,所以如果你想要八月,你应该使用7