我有一個TextBox
和CalendarExtender
的頁面,它應該允許我檢測選擇的日期。但是,這是報告未選擇的日期。CalendarExtender表示選擇了錯誤的日期,可能與時區有關
<asp:TextBox ID="tbEffectiveDate" runat="server"
CssClass="input-small"
MaxLength="10"
Text='<%# Bind("NewEffectiveDate", "{0:MM/dd/yyyy}") %>'>
</asp:TextBox>
<ajaxToolkit:CalendarExtender ID="atkEffectiveDate" runat="server"
FirstDayOfWeek="Sunday"
TargetControlID="tbEffectiveDate"
Format="MM/dd/yyyy"
OnClientDateSelectionChanged="CheckForSunday">
</ajaxToolkit:CalendarExtender>
基本上我確保用戶選擇了一個星期日,但是當我在日曆上選擇一天時,JavaScript表示它是前一天。我很困惑。
function CheckForSunday(sender, args) {
var selectedDate = new Date();
selectedDate = sender.get_selectedDate();
// Both of these show the date before the date was selected
alert(sender.get_selectedDate());
if (selectedDate.getDay() != 0) {
// not a Sunday
var sunday = selectedDate;
// calculated the nearest Sunday
sunday.setDate(selectedDate.getDate() - selectedDate.getDay());
sender.set_selectedDate(sunday);
// tell the user that the date wasn't a Sunday
// and that the previous Sunday was selected.
$("#must-be-sunday").modal("show");
}
}
例如,如果我選擇一個星期天,如5月5日:
然後在該行alert(sender.get_selectedDate());
,它顯示
這話說週五,5月4日被選中,而不是5月5日。因爲在我的語言環境中,我們是-0700,這是在5日午夜前7小時顯示的,我猜這與時區有關。
有誰知道可能是什麼原因導致這種情況,以及如何解決它,所以它不適用於時間和只選擇日期?