在 jquery datetimepicker 中设置最大和最小日期时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38045507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:09:28  来源:igfitidea点击:

Set max and min datetime in jquery datetimepicker

jquerydatetimepicker

提问by Shashikala

I am using jquery datetimepicker.In which i want to set mindate and time which is the value selected in second datetimepicker.

我正在使用 jquery datetimepicker。在其中我想设置思维和时间,这是在第二个 datetimepicker 中选择的值。

What i tried is :

我试过的是:

$('#date_start').datetimepicker({
        autoSize: true,
        changeYear: true,
        changeMonth: true,
        buttonImageOnly: true,
        onSelect: function (selected) {
             $('#date_end').datetimepicker("option", "minDate", selected);
        }
    });

I refered this Jquery - DateTimePicker set max datetimelink.But its not a clear solution for my issue.

我参考了这个Jquery - DateTimePicker set max datetimelink.但它不是我的问题的明确解决方案。

$('#date_end').datetimepicker({
        autoSize: true,
        changeYear: true,
        changeMonth: true,
        buttonImageOnly: true,
        onSelect: function (selected) {
            $('#date_start').datetimepicker("option", "maxDate", selected);
        }
    });

Actually this same code is working for only datepicker.But if i want it to work in datetimepicker.

实际上,相同的代码仅适用于 datepicker。但如果我希望它在 datetimepicker 中工作。

What is the solution?

解决办法是什么?

回答by Shaunak D

In the pluginyou have provided, there is no option like onSelect.

在您提供的插件中,没有像onSelect.

Use onSelectDateand onSelectTimeor onShow,

使用onSelectDateonSelectTimeonShow,

$('#date_start').datetimepicker({
    minDate:'-1970/01/02',
    minTime:'11:00'
});

or at runtime,

或在运行时,

var setMin = function( currentDateTime ){
  this.setOptions({
      minDate:'-1970/01/02'
  });
  this.setOptions({
      minTime:'11:00'
  });
};

$('#date_start').datetimepicker({
    onShow:setMin
});

References:

参考:

  1. minDate
  2. maxDate
  3. minTime
  4. maxTime
  1. 最小日期
  2. 最大日期
  3. 最小时间
  4. 最大时间