jQuery 在 Bootstrap DateTimePicker 中将 minDate 设置为 Today
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27095415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set minDate to Today in Bootstrap DateTimePicker
提问by Giantsfan542
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?
我正在使用 Bootstrap DateTime Picker ( http://eonasdan.github.io/bootstrap-datetimepicker/),我找到了设置 minDate 的基本选项;但是,我无法将其设置为今天以挽救我的生命。我试过 Date(); 之类的东西。但是,没有任何效果。谁有想法?
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()
});
回答by Bart Jedrocha
If you're using the latest version, the minDate
option is what you'll need to set. Here is a JSFiddlewith a working example. Hope this helps.
如果您使用的是最新版本,则minDate
需要设置该选项。这是一个带有工作示例的JSFiddle。希望这可以帮助。
$('#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()
});
回答by Jah Yusuff
$(".datepicker-custom-flight").datepicker({
startDate: "dateToday"
})
回答by shijinmon Pallikal
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
});