我想在幾秒鐘內找到兩個日期(或時間,不知道該怎麼說)之間的差異。時差返回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