どの日付が選択されているかを検出できると思われるaTextBox
とa のページがあります。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 月 5 日の代わりに 5 月 4 日の土曜日が選択されていることを示しています。私のロケールでは -0700 で、これは 5 日の真夜中の 7 時間前を表示しているので、これはタイムゾーンと関係があると推測しています。
これを引き起こしている可能性のあるものと、それを修正する方法を知っている人はいますか?