[英]DateTimePicker: function add remove day from minDate maxDate
I'm having a bit of trouble with the DateTimePicker by XDSOFT. XDSOFT的DateTimePicker有点麻烦。 I'm trying to add and remove a day from the minDate and maxDate in the onShow function of the DateTimePicker.
我试图在DateTimePicker的onShow函数中的minDate和maxDate中添加和删除一天。
jQuery(function(){
$('.start-date').datetimepicker({
format: 'd/m/y H:i',
onShow: function (ct) {
this.setOptions({
maxDate: getEndDate($('#end-date-input').val()),
formatDate: 'd/m/y H:i'
})
},
timepicker:true,
onChangeDateTime: function (current_time, $input) {
var inputDate;
inputDate = $input.val();
$('#start-date-input').val(inputDate);
$('.start-date').children().attr('data-original-title', inputDate);
console.log(inputDate)
}
});
$('.end-date').datetimepicker({
format: 'd/m/y H:i',
onShow: function (ct) {
this.setOptions({
minDate: getStartDate($('#start-date-input').val()),
formatDate: 'd/m/y H:i'
})
},
timepicker:true,
onChangeDateTime: function (current_time, $input) {
var inputDate;
inputDate = $input.val();
$('#end-date-input').val(inputDate);
$('.end-date').children().attr('data-original-title', inputDate);
console.log(inputDate)
}
});
});
function getStartDate(date_input) {
var from_date = new Date(date_input);
return new Date(from_date.setDate(from_date.getDate() + 1));
}
function getEndDate(date_input) {
var from_date = new Date(date_input);
return new Date(from_date.setDate(from_date.getDate() - 1));
}
Is there a problem with my function ? 我的功能有问题吗?
Months later, but still might help someone. 几个月后,但仍然可以帮助某人。
I think your date might not take properly the "+1" and "-1" on your "from_date.getDate() + 1" and "from_date.getDate() - 1" parts. 我认为您的日期可能不正确地包含“ from_date.getDate()+ 1”和“ from_date.getDate()-1”部分中的“ +1”和“ -1”。
It might be understood as "Add 1" or "Remove 1" to the timestamps. 可以将其理解为时间戳的“添加1”或“删除1”。 try to do something like "+/- 60 * 60 * 24"
尝试做类似“ +/- 60 * 60 * 24”的操作
Might work. 可能会工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.