简体   繁体   English

DateTimePicker:函数从minDate maxDate添加删除日期

[英]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.

相关问题 jQuery datetimepicker异常日,带有minDate和maxDate - JQuery datetimepicker exception day with minDate and maxDate 修改链接的datetimepicker minDate maxDate函数 - Modifying linked datetimepicker minDate maxDate function 是否可以在 Tempus Dominus bootstrap 4 datetimepicker 中将 minDate 和 maxDate 设置为同一天? - Is it possible to set minDate and maxDate to the same day in Tempus Dominus bootstrap 4 datetimepicker? 如何在 Bootstrap DateTimePicker 上允许 maxDate 和 minDate 相等? - How to allow maxDate and minDate to be equal on Bootstrap DateTimePicker? 可观察到的淘汰赛中的datetimepicker引导程序minDate和maxDate - datetimepicker bootstrap minDate and maxDate in observable knockout 如何在更改时为引导程序datetimepicker设置minDate和maxDate - How to set minDate and maxDate for bootstrap datetimepicker on change 无法在jquery-simple-datetimepicker中设置minDate或maxDate - Impossible to set minDate or maxDate in jquery-simple-datetimepicker jQuery datepicker从jsp设置minDate和maxDate - jquery datepicker set minDate and maxDate from jsp jQueryUI DatePicker-将单击事件添加到minDate和maxDate之外的日期 - jQueryUI DatePicker - Add click events to dates outside of minDate and maxDate mindate和maxdate在datepicker中不起作用 - mindate and maxdate not working in datepicker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM