How do I set a timer to only set the time from 8:30 am to 8:30 pm in bootstrap-datetimepicker.js?
HTML CODE:
<div class="form-group">
<label class="col-md-3 control-label" for="event_date">Start at</label>
<div class="col-md-8">
<input id="event_start_date" name="event_start_date" type="text" placeholder="" class="form-control input-md event_date" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" for="event_date">End at</label>
<div class="col-md-8">
<input id="event_end_date" name="event_end_date" type="text" placeholder="" class="form-control input-md event_date" required="">
</div>
</div>`
JavaScript code:
$('#event_start_date').datetimepicker({
minTime: "08:30:00"
});
I need to set the start time of the timepicker to be 8:30 AM to the end of the time, since 8:30 PM disable other times in the timepicker. How is it possible, please help?
+3
source to share
3 answers
There are no docs here, but I found the following items are the key.
Understand that the datetimepicker uses the moment.js library.
DisabledTimeIntervals takes an array of arrays that define the time range.
[ //outer array [ start_time, end_time], [ second_start_time, second_end_time] ]
Another key point is that when you define a moment, you need to specify the hour and minute, leaving the default so that the filter won't work for me.
So, if you wanted to define a store that was open from 8:30 am to 8:30 pm with a 30 minute one, it would look like this:
$('.event_date').datetimepicker({
disabledTimeIntervals: [
[moment().hour(0).minutes(0), moment().hour(8).minutes(30)],
[moment().hour(20).minutes(30), moment().hour(24).minutes(0)]
]
});
+9
source to share