This is a migrated thread and some comments may be shown as answers.

How to subtract timezone offset value from RadDateTimePicker selected Datetime value on Client side.

4 Answers 221 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vincy
Top achievements
Rank 1
Vincy asked on 20 May 2014, 07:18 AM
Hi All,

I have a RadDateTimePicker control, in which I have defined  <ClientEvents OnDateSelected="DateSelected" />.

function DateSelected(sender, eventArgs)
    {
       var dtp = $find("<%= RadDateTimePicker1.ClientID %>");
       var selDate = dtp.get_selectedDate();
      
    }

selDate shows the result as :  Fri May 16 2014 00:00:00 GMT+0530 (India Standard Time)

My Issue is:   After selecting date from calendar, whatever time I select from the TimePicker,  It always shows 5:30 hours ahead of the selected time.
for eg.  Suppose I select 2:00 PM, then It will show 7:30 PM as the selected time.


Please suggest some wayout.

Thanks a lot.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 May 2014, 08:49 AM
Hi Vincy,

Please have a look into the sample code snippet which works fine at my end. In the attached image 'SelectDate.png' shows the 'SelDate' variable value when selecting the date. Next Image 'changetime.png' shows the 'SelDate' variable value after changing the time to 2:00 PM. 

ASPX:
<telerik:RadDateTimePicker ID="RadDateTimePicker1" runat="server" ClientEvents-OnDateSelected="DateSelected">
</telerik:RadDateTimePicker>

JavaScript:
function DateSelected(sender, args) {
    var datetime = $find("<%=RadDateTimePicker1.ClientID%>");
    var selDate = datetime.get_selectedDate();
}

Please provide your code if it doesn't help.
Thanks,
Princy.
0
Vincy
Top achievements
Rank 1
answered on 20 May 2014, 12:19 PM
Hi, thanks for your efforts..but this didn't worked.
I am posting my code snippet here..
// below code is used to display 11:59 in the time picker.

 if (!Page.IsPostBack)
            {

                List<DateTime> dateList = new List<DateTime>();

                for (int hour = 0; hour < 24; hour++)
                      dateList.Add(DateTime.UtcNow.Date.AddHours(hour));

                dateList[0] = dateList[0].AddDays(1).AddMinutes(-1);

                RadDateTimePicker1.TimeView.DataList.DataSource = dateList;
          
            }

Now whenever I select time from the TimePicker,  It always shows 5:30 hours ahead of the selected time.
0
Princy
Top achievements
Rank 2
answered on 21 May 2014, 11:26 AM
Hi Vincy,

Unfortunately I couldn't replicate the issue at my end. The given code was working fine at my end.

Thanks,
Princy.
0
Vincy
Top achievements
Rank 1
answered on 21 May 2014, 12:17 PM
Hi Princy,
Thanks for your efforts ..and this time I got it worked fine...
I simply changed the line1 with line 2.

line1: dateList.Add(DateTime.UtcNow.Date.AddHours(hour));

line2: dateList.Add(DateTime.Now.Date.AddHours(hour));

After doing this, now the Time is showing as 11:59:00 PM instead of 12:00:00 A.M, and after time selection also, the exact time selected is displayed ie. no GMT time get added to it.

glad it worked :)

Thanks


Tags
General Discussions
Asked by
Vincy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Vincy
Top achievements
Rank 1
Share this question
or