Set minDate to Today in Bootstrap DateTimePicker

▼魔方 西西 提交于 2020-01-01 04:22:08

问题


I'm using Bootstrap DateTime Picker (http://eonasdan.github.io/bootstrap-datetimepicker/) and I've found the basic option to set a minDate; but, I can't get it to set to today to save my life. I've tried things like Date(); but, nothing working. Anyone have any ideas?

Example

    $('#date').datetimepicker({
        pickTime: false,
        icons: {
                time: "fa fa-clock-o",
                date: "fa fa-calendar",
                up: "fa fa-arrow-up",
                down: "fa fa-arrow-down"
            },
        startDate: new Date()
    });

回答1:


If you're using the latest version, the minDate option is what you'll need to set. Here is a JSFiddle with a working example. Hope this helps.

$('#date').datetimepicker({
    pickTime: false,
    icons: {
      time: "fa fa-clock-o",
      date: "fa fa-calendar",
      up: "fa fa-arrow-up",
      down: "fa fa-arrow-down"
    },
    minDate: moment()
});



回答2:


$(".datepicker-custom-flight").datepicker({
	startDate: "dateToday"
})



回答3:


You can use this code, by avoiding additional scripts.

Example

var todayDate = new Date().getDate();
var endD= new Date(new Date().setDate(todayDate - 15));
var currDate = new Date();
$('.datepicker').datepicker({
    format: 'dd/mm/yyyy',                       
    autoclose: true,
    startDate : endD,
    endDate : currDate
});


来源:https://stackoverflow.com/questions/27095415/set-mindate-to-today-in-bootstrap-datetimepicker

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