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

5 posts, 0 answers
  1. Vincy
    Vincy avatar
    10 posts
    Member since:
    Aug 2013

    Posted 20 May 2014 Link to this post

    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.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 May 2014 in reply to Vincy Link to this post

    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.
  3. Vincy
    Vincy avatar
    10 posts
    Member since:
    Aug 2013

    Posted 20 May 2014 in reply to Princy Link to this post

    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.
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 May 2014 in reply to Vincy Link to this post

    Hi Vincy,

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

    Thanks,
    Princy.
  5. Vincy
    Vincy avatar
    10 posts
    Member since:
    Aug 2013

    Posted 21 May 2014 in reply to Princy Link to this post

    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


Back to Top