如何获取Bootstrap-daterange选择器的日期差。我使用下面的代码,但给了我错误值。有人可以建议做什么吗?
$(function () {
'use strict';
$('input[name="dates"]').daterangepicker({
autoUpdateInput: false,
}).on('apply.daterangepicker', function (ev, picker) {
$('#fromdate').val(picker.startDate.format('DD-MM-YYYY'));
$('#todate').val(picker.endDate.format('DD-MM-YYYY'));
var start = picker.startDate.format('DD-MM-YYYY');
var end = picker.endDate.format('DD-MM-YYYY');
var startD = new Date(start);
var endD = new Date(end);
var diff = parseInt((endD.getTime()-startD.getTime())/(24*3600*1000));
// $("#days").val(diff);
alert(diff);
$(this).val(picker.startDate.format('DD MMM YYYY') + ' -to- ' + picker.endDate.format('DD MMM YYYY'));
});
$('input[name="dates"]').on('cancel.daterangepicker', function (ev, picker) {
$(this).val('');
});
});