Bootstrap日期选择器禁用没有当前日期的过去日期 [英] Bootstrap datepicker disabling past dates without current date
问题描述
我想禁用当前日期之前的所有过去日期,而不是当前日期.我正在尝试通过 bootstrap datepicker 库bootstrap-datepicker"并使用以下代码:
I wanted to disable all past date before current date, not with current date. I am trying by bootstrap datepicker library "bootstrap-datepicker" and using following code:
$('#date').datepicker({
startDate: new Date()
});
它工作正常.但它是禁用日期直到今天.
It works fine. But it is disabling date till today.
例如,如果今天是 04-20-2013,我通过设置 startDate: new Date() 禁用过去的日期.但我可以选择 04-21-2013 的日期.
As example if today is 04-20-2013 and i disable past dates by setting startDate: new Date(). but I am able to select date from 04-21-2013.
更新:对于UTC区域,我可以按以下方式解决它:
UPDATED: i can solve it as following for UTC zone:
var d = new Date();
options["startDate"] = new Date(d.setDate(d.getDate() - 1));
或 startDate: "+0d"
但是当 UTC 提前一天时,这些方法不起作用.对于我在加利福尼亚的客户,这意味着在下午 5:00 我的客户不能再选择他当地的当前日期作为有效日期.为了解决这个问题,我暂时使用了 startDate: "-1d"
,但当然在 5 之前这意味着昨天是可见的.
But these methods don't work when UTC is a day ahead. For my client in California that means at 5:00 pm my client can no longer select his local current date as a valid date. In order to fix this I am temporarily using startDate: "-1d"
, but of course before 5 that means yesterday is visible.
现在有没有人想出更好的方法,因为我不想告诉用户输入 UTC 日期?
Has anyone come up with a better method for now as I do not want to tell users to put in a UTC date?
提前致谢.
推荐答案
var date = new Date();
date.setDate(date.getDate()-1);
$('#date').datepicker({
startDate: date
});
这篇关于Bootstrap日期选择器禁用没有当前日期的过去日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!