Shekhar R
Shekhar R

Reputation: 81

Set start time and end time for bootstrap timepicker

I'm using bootstrap timepicker and I need it to show time only between 10 AM and 10 PM. I've checked through the options and there seems to be no option for this. Is there any other way that I've missed for doing this?

Upvotes: 1

Views: 5134

Answers (2)

Shekhar R
Shekhar R

Reputation: 81

I've found a way to set start time and end time for bootstrap timepicker finally. Adding the below code will get it working. In my code, its showing from 10 AM to 10 PM.

$('#timepicker').timepicker().on('changeTime.timepicker', function (e) {

    var hour = e.time.hours;
    if (e.time.meridian === "PM" && hour !== 12) {
        hour += 12;
    }
    hour += (e.time.minutes / 100);
    if (hour < 10) {
        $('#timepicker').timepicker('setTime', '10:' + e.time.minutes + ' AM');
    }
    else if (hour > 22) {
        $('#timepicker').timepicker('setTime', '10:' + e.time.minutes + ' AM');
    }
});

Upvotes: 1

lchabrand
lchabrand

Reputation: 165

you can passe an array disabledTimeIntervals to your datepicker. For exemple :

$('#mydatepicker').datetimepicker( {
disabledTimeIntervans :
    [
    [moment().hour(0), moment().hour(10).minutes(00)],
    [moment().hour(0), moment().hour(22).minutes(00)]
    ]
});

Upvotes: 0

Related Questions