Bootstrap datetimepicker startDate does not disable past dates

泪湿孤枕 提交于 2019-12-02 07:32:27

问题


I use bootstrap datetimepicker and I want to disable the past days but startDate option did not work:

var now = new Date();
var tomorrow = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + (now.getDate() + 1) + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
$('#end_at').datetimepicker({
    format: 'YYYY-MM-DD hh:mm:ss',
    startDate: tomorrow
});

回答1:


You probably need to use the minDate option of the datetimepicker:

var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
$("#end_at").datetimepicker({
    format: 'YYYY-MM-DD HH:mm:ss',
    minDate: tomorrow
});



回答2:


startDate api will helps to disable past date

<script type="text/javascript">
     $(function() {
        $(".dates").datepicker({
        format:'dd-mm-yyyy',
        startDate:new Date(),
        autoclose:true
});
</script>



回答3:


It's been a long time. The option minDate is deprecated. the new one is startDate

So you can use:

<script type="text/javascript">
    $(".form_datetime").datetimepicker({
        format: "dd MM yyyy - hh:ii",
        autoclose: true,
        todayBtn: true,
        startDate: "2013-02-14 10:00",
        minuteStep: 10
    });
</script> 


来源:https://stackoverflow.com/questions/33210085/bootstrap-datetimepicker-startdate-does-not-disable-past-dates

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