javascript - CalendarExtender saying the wrong date is selected, possibly timezone related -
i have page textbox
, calendarextender
supposed allow me detect date selected. however, reporting date isn't selected.
<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>
essentially i'm making sure user has selected sunday, when select day on calendar, javascript says day before. i'm perplexed.
function checkforsunday(sender, args) { var selecteddate = new date(); selecteddate = sender.get_selecteddate(); // both of these show date before date selected alert(sender.get_selecteddate()); if (selecteddate.getday() != 0) { // not sunday var sunday = selecteddate; // calculated nearest sunday sunday.setdate(selecteddate.getdate() - selecteddate.getday()); sender.set_selecteddate(sunday); // tell user date wasn't sunday // , previous sunday selected. $("#must-be-sunday").modal("show"); } }
for example, if select sunday, such may 5th:
then @ line alert(sender.get_selecteddate());
, displays
this saying saturday, may 4th selected instead of may 5th. since in locale, -0700 , displaying 7 hours before midnight on 5th, i'm guessing has timezone.
does know may causing , how fix doesn't work time , date selected?
you right problem due timezones calendarextender use utc dates each day cell value. if want check day of week selected may use date.getutcday()
function instead of date.getday()
, getutcdate()
instead of getdate()
in onclientdateselectionchanged
handler.
Comments
Post a Comment