Javascript 日期差大于预期值
我正在学习在Javascript中使用日期对象。试图计算“现在”和某个设定日期之间的差值,但它返回的值比inteded的值大得多。密码笔是,我似乎不知道我做错了什么。。。帮忙Javascript 日期差大于预期值,javascript,datetime,Javascript,Datetime,我正在学习在Javascript中使用日期对象。试图计算“现在”和某个设定日期之间的差值,但它返回的值比inteded的值大得多。密码笔是,我似乎不知道我做错了什么。。。帮忙 var setdate = new Date(2014, 4, 27, 14,30); //27th of April this year at 14:30 var now = new Date(); //Now, whenever this code runs var diff = Math.round((setdate
var setdate = new Date(2014, 4, 27, 14,30); //27th of April this year at 14:30
var now = new Date(); //Now, whenever this code runs
var diff = Math.round((setdate.getTime() - now.getTime())/1000); //Difference in seconds
function NiceTimer(delta) { //Decompose the difference in seconds into date units.
this.days = Math.floor(delta/ 86400);
delta -= this.days*86400; //Subtract the value once it has been "extracted".
this.hours = Math.floor(delta/ 3600);
delta -= this.hours*3600;
this.minutes = Math.floor(delta/ 60);
delta -= this.minutes*60;
this.seconds = delta;
this.printString = function() {
return "The event starts in "+this.days+" days, "+this.hours+" hours, "+this.minutes+" minutes and "+this.seconds+" seconds"; //Output a readable countdown string
}
}
var timer = new NiceTimer(diff);
var el = document.getElementById("timer");
el.innerHTML = timer.printString();
将四个月改为三个月,从指数0开始
var setdate = new Date(2014, 3, 27, 14,30);
:
月份
表示月份的整数值,1月从0开始,12月从11开始
将四个月改为三个月,从指数0开始
var setdate = new Date(2014, 3, 27, 14,30);
:
月份
表示月份的整数值,1月从0开始,12月从11开始
请在StackOverflow上发布有问题的代码,而不是其他地方。如果太长,则将其缩短到相关部分。请在StackOverflow上发布有问题的代码,而不是其他地方。如果它太长,那么就把它缩短到相关的部分。啊哈?世界跆拳道联盟。。。那就像。。。完全不合逻辑。谢谢啊哈,斯雷?世界跆拳道联盟。。。那就像。。。完全不合逻辑。谢谢