Bootstrap datepicker禁用过去的日期而没有当前日期 [英] Bootstrap datepicker disabling past dates without current date

查看:373
本文介绍了Bootstrap datepicker禁用过去的日期而没有当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用当前日期之前的所有过去日期,而不是当前日期。我正在尝试使用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()来禁用过去的日期。但是我可以选择2013年11月21日的日期。

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点,我的客户不能再选择他当地的当前日期作为有效日期。为了解决这个问题,我暂时使用 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 datepicker禁用过去的日期而没有当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆