jQuery Bootstrap DatePicker,如何设置明天的开始日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14409779/
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
Bootstrap DatePicker, how to set the start date for tomorrow?
提问by evanx
How can I set the startDate for tomorrow? I don't see an option in the documentation for Date.today so I can add one more day.
如何设置明天的开始日期?我在 Date.today 的文档中没有看到选项,所以我可以再添加一天。
Is there a way to accomplish this?
有没有办法做到这一点?
$(function() {
$("#appointment_adate").datepicker({
format: 'yyyy-mm-d',
autoclose: true,
startDate: '+1d'
});
});
回答by eternicode
There is no official datepicker for bootstrap; as such, you should explicitly state which one you're using.
没有用于引导程序的官方日期选择器;因此,您应该明确说明您使用的是哪一个。
If you're using eternicode/bootstrap-datepicker, there's a startDateoption. As discussed directly under the Options sectionin the README:
如果您使用的是eternicode/bootstrap-datepicker,则有一个startDate选项。正如在自述文件中的选项部分直接讨论的那样:
All options that take a "Date" can handle a Date object; a String formatted according to the given format; or a timedelta relative to today, eg '-1d', '+6m +1y', etc, where valid units are 'd' (day), 'w' (week), 'm' (month), and 'y' (year).
所有带“日期”的选项都可以处理日期对象;根据给定格式格式化的字符串;或相对于今天的时间增量,例如“-1d”、“+6m +1y”等,其中有效单位为“d”(天)、“w”(周)、“m”(月)和“y” ' (年)。
So you would do:
所以你会这样做:
$('#datepicker').datepicker({
startDate: '+1d'
})
回答by heads5150
If you are talking about Datepicker for bootstrap, you set the start date (the min date) by using the following:
如果您正在谈论用于 bootstrap 的 Datepicker,您可以使用以下命令设置开始日期(最小日期):
$('#datepicker').datepicker('setStartDate', <DATETIME STRING HERE>);
回答by Vishnu Vardhana
this.$('#datepicker').datepicker({minDate: 1});
minDate:0
- Enable dates in the calender from the current date. MinDate:1
enable dates in the calender currentDate+1
minDate:0
- 从当前日期启用日历中的日期。MinDate:1
在日历中启用日期currentDate+1
To Restrict date between from tomorrow and the same day next month u need to give something like
要限制从明天到下个月同一天之间的日期,你需要给出类似的东西
$( "#datepicker" ).datepicker({ minDate: 1, maxDate: "+1M" });
回答by Sinan Eldem
If you are using bootstrap-datepickeryou may use this style:
如果您使用的是bootstrap-datepicker,您可以使用这种样式:
$('#datepicker').datepicker('setStartDate', "01-01-1900");
回答by Pushkar Mehta
1) use for tommorow's date startDate: '+1d'
1) 用于明天的日期 startDate: '+1d'
2) use for yesterday's date startDate: '-1d'
2) 用于昨天的日期 startDate: '-1d'
3) use for today's date startDate: new Date()
3) 用于今天的日期 startDate: new Date()