我想计算 startdatetime 和 enddatetime 之间的差异
这是我的html代码:
StartDate:<input size="16" type="text" placeholder="YYYY-MM-DD" id="from_date" name="from_date" value="">
Enddate:<input size="16" type="text" placeholder="YYYY-MM-DD" id="to_date" name="to_date" onchange="calservicedays();" value="">
StartDate:2013-09-07 11:09:40
Enddate:2013-09-08 11:15:50
下面是我的javascript代码
function calservicedays(){
var start = $("#from_date").val();
var startDate = new Date(start);
var end = $("#to_date").val();
var endDate = new Date(end);
var startcom = Date.parse(start);
var endcom = Date.parse(end);
var diff = Math.floor((endDate.getTime() - startDate.getTime()) / 86400000);
if((startDate != null && endDate != null) && (start != '' && end != '')){
if((startDate != null && endDate != null) && (start != '' && end != '') && (startcom < endcom)){
var diff = Math.floor((endDate.getTime() - startDate.getTime()) / 86400000);
if(diff != "")
$("#service").val(diff);
}else{
alert("To Date cannot be less than or equal to From date");
$("#service").val('');
return false;
}
}
}
有了这个 javascript 代码,我就在几天之内得到了不同。我想要天和时间的差异。
谁能告诉我我必须在我的javascript代码中进行哪些更改才能获得日期和时间的差异。
谢谢