我想在几秒钟内找到两个日期(或时间,不知道该怎么说)之间的差异。时差返回NaN
这里是代码:
var montharray = new Array ("Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sept" , "Oct" , "Nov" , "Dec")
function time_difference (yr,m,d,h,mins,sec){
var today = new Date();
var this_year = today.getYear();
if (this_year<1000)
this_year+=1900;
var this_month= today.getMonth();
var this_day=today.getDate();
var this_hour=today.getHours();
var this_mins=today.getMinutes();
var this_secs=today.getSeconds();
var today_string=montharray[this_month]+" "+this_day+", "+this_year+" "+this_hour+" "+this_mins+" "+this_secs;
var disconnect_string=montharray[m-1]+" "+d+", "+yr+" "+h+" "+mins+" "+sec;
var difference=(Math.round((Date.parse(disconnect_string)-Date.parse(today_string))/1000)*1)
alert(difference);
}
time_difference(2014,4,13,16,0,0)
(在我的国家,当我问的问题时间为15:26)
但警报显示我的NaN。
,但是当我只用年,月,日返回预期的结果,1
一些错误的标点符号或...?
谢谢你,帮助!这可能是做我想做的最简单的方法。 – yamahamm