本文介绍了bootstrap datetimepicker-设置相对于现在的maxDate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此datetimepicker:
http://eonasdan.github.io/bootstrap-datetimepicker/Options/
基本上我想设置maxDate: moment(),即maxDate应该限于现在.问题在于打开日期选择器时,maxDate不再是now()了.我想在每次显示日期选择器时将其maxDate设置为现在.

I use this datetimepicker:
http://eonasdan.github.io/bootstrap-datetimepicker/Options/
Basically I want to set maxDate: moment(), i.e maxDate should be limited to now.The problem is by the time the datepicker is opened maxDate is not now() anymore. I want to set it maxDate to now everytime the datepicker is shown.

如果可能的话,我想在全球范围内强制实施,而不是在每个datetimepicker()实例上都进行指定.是否可以使用moment.js以某种方式给出相对于现在的日期?

I want to enforce it globally if possible, not to specify it on every datetimepicker() instance. Is it possible to somehow give a relative date to now using moment.js ?

查看此小提琴:
https://jsfiddle.net/0Ltv25o8/3281/
我将maxDate设置为现在.您会在页面加载分钟后看到,您将无法使用箭头按钮选择当前分钟.

See this fiddle:
https://jsfiddle.net/0Ltv25o8/3281/
I set maxDate to now. You'll see after minute from the page load, you won't be able to choose the current minutes using the arrow buttons.

推荐答案

如何使用自定义版本的datepicker插件?

How about using custom version of datepicker plugin?

我添加了新参数maxDateNow(对更好的名称有任何想法吗?),该参数可以选择直到当前时间的日期/时间.

I have added new parameter maxDateNow (any ideas for a better name?) that allows selecting date/time up to present time.

$('#datetimepicker1').datetimepicker({maxDateNow: true, format:'DD/MM/YYYY HH:mm'});

请参见小提琴

这篇关于bootstrap datetimepicker-设置相对于现在的maxDate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 06:46