最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to limit Min-Max Time in bootstrap datetimepicker - Stack Overflow

programmeradmin4浏览0评论

How to limit

I'm trying to limit the time a user can select from this plugin:

I've searched around this site and google for similar questions, but users generally ask for the validation to work between one known period and another known period. e.g 9:00 - 21:00 2015/03/09 9:00 - 2015/03/10 21:00. If a user inputs 2015/03/09 23:00 the validation will pass this because the time is within those two min/max periods.

I need it to work as a booking system works, so that each day is limited between those times. e.g if a user selects 2015/03/09 23:00 or 2015/03/10 5:00 then the validation won't pass, it will only pass on any day between 9:00 & 21:00.

    $('.datetimepicker').datetimepicker({
       stepping: 30,
       minDate: moment({hour: 9, minute: 30}),
       format: 'YYYY-MM-DD HH:mm'
    });

This starts the min date for today at 9:30am, but if I was to choose any day after today I would be able to select for example 4am - anything under 9:30am

How to limit

I'm trying to limit the time a user can select from this plugin: https://github./Eonasdan/bootstrap-datetimepicker

I've searched around this site and google for similar questions, but users generally ask for the validation to work between one known period and another known period. e.g 9:00 - 21:00 2015/03/09 9:00 - 2015/03/10 21:00. If a user inputs 2015/03/09 23:00 the validation will pass this because the time is within those two min/max periods.

I need it to work as a booking system works, so that each day is limited between those times. e.g if a user selects 2015/03/09 23:00 or 2015/03/10 5:00 then the validation won't pass, it will only pass on any day between 9:00 & 21:00.

    $('.datetimepicker').datetimepicker({
       stepping: 30,
       minDate: moment({hour: 9, minute: 30}),
       format: 'YYYY-MM-DD HH:mm'
    });

This starts the min date for today at 9:30am, but if I was to choose any day after today I would be able to select for example 4am - anything under 9:30am

Share Improve this question asked Mar 9, 2015 at 11:08 MikeyBeLikeMikeyBeLike 8331 gold badge9 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

Use the enabledHours property:

$('.datetimepicker').datetimepicker({
   stepping: 30,
   enabledHours: [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
   format: 'YYYY-MM-DD HH:mm'
});

This way it should allow any hours between 9:00 and 20:30, but won't allow anything from 21:00 on. More at http://eonasdan.github.io/bootstrap-datetimepicker/Options/#endisabledhours.

发布评论

评论列表(0)

  1. 暂无评论