How to set time picker only set time from 8:30 am to 8:30 pm in bootstrap-datetimepicker.js?

怎甘沉沦 提交于 2019-12-03 05:04:27

The docs are lacking here, but I found that the following items are the key.

Understand that the datetimepicker uses the moment.js library.

The disabledTimeIntervals takes an array of arrays that define a time range.

[ //outer array
  [ start_time, end_time],
  [ second_start_time, second_end_time]
]

The other key point is that when you define a moment, you need to include the hour and minute, leaving the defaults caused the filter to no work for me.

So if you wanted to define a shop that was open from 8:30 AM to 8:30 PM with a 30 minute, it would look as follows:

$('.event_date').datetimepicker({
    disabledTimeIntervals: [
      [moment().hour(0).minutes(0), moment().hour(8).minutes(30)],
      [moment().hour(20).minutes(30), moment().hour(24).minutes(0)]
   ]
});

Here i solved my problem with this code:

$('.event_date').datetimepicker({
        disabledTimeIntervals: [ [ moment().hour(0), moment().hour(8).minutes(30) ], [ moment().hour(20).minutes(30), moment().hour(24) ] ]
    });

Haven't tried it myself but from the docs,

disabledTimeIntervals
4.14.40

Default: false
Disables time selection between the given moments
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!