我在转换时遇到了一些麻烦。它说日期无效alert(first_date) and alert(end_date)
,等等:s 我使用 datetimepicker 来获取日期。
$( "#start_date" ).datetimepicker({
dateFormat : 'yy-mm-dd',
timeFormat: 'hh:mm:ss',
defaultDateTime: "+1w",
showSecond: true,
changeMonth: true,
changeYear: true,
onClose: function( selectedDateTime ) {
$( "#end_date" ).datetimepicker( "option", selectedDateTime );
}
});
$( "#end_date" ).datetimepicker({
dateFormat : 'yy-mm-dd',
timeFormat: 'hh:mm:ss',
defaultDateTime: "+1w",
showSecond: true,
changeMonth: true,
changeYear: true,
onClose: function( selectedDateTime ) {
$( "#start_date" ).datetimepicker( "option", selectedDateTime );
}
});
现在,我需要做这样的事情:
var first_date = new Date($('#start_date').val());
var last_date = new Date($('#end_date').val());
var nDifference = (last_date - first_date);
var one_day = 1000*60*60*24;
var days = Math.round(nDifference/one_day);
<input type="text" id="start_date" name="start_date" value=""/>
<input type="text" id="end_date" name="end_date" value=""/>