2016-02-25 70 views
0

如何獲得從當前時間到小時開始日期的小時差異?獲取時差(小時)

var diff = new Date("2016-02-26 17:21:29") - new Date(); 
diff_time = diff/(60 * 60 * 1000); 
//alert(diff_time); 

if (diff_time < 24) { 
    alert("Please select the start date greater than 24 hours"); 
} 

回答

0

時間格式應該是/或空格分隔,不-分離

var diff = new Date($('#start_date').val()) - new Date() ; 
diff_time = diff/(60 * 60 * 1000); 
alert(diff_time); 
return false; 

if (diff_time < 24) { 
    error = "Please select the start date on"; 
}