+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / DateTime picker time results shown 4 hours ahead

DateTime picker time results shown 4 hours ahead

3 posts, 1 answered
  1. Chip
    Chip avatar
    14 posts
    Registered:
    25 Nov 2013
    25 Mar 2015
    Link to this post

    I have a custom field for pages that uses datetime picker. It works fine but when I go to display that date time on a page the time doesn't match the selected time. It seems to always be 4 hours ahead of what I choose. Of course it's all in military time on the backend. 

    For example: 

    If I choose in the backend: 04/10/2015 16:00

    And I display on the front end:

    string displayDate = saleDateTime.ToLongDateString();
    string displayTime = saleDateTime.ToShortTimeString(); 

    displayTime shows 8:00pm

     If I choose in the backend: 04/10/2015 10:00

     displayTime shows 2:00pm

     

    Why is it 4 hours ahead of the time I choose in the custom field? 

    Answered
  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    30 Mar 2015
    Link to this post
    Hello Chip,

    The date/time is save in the database in UTC. In order to show the date/time in the current time you can call the method ".ToLocalTime()". In that case your code would be:
    string displayDate = saleDateTime.ToLocalTime().ToLongDateString();
    string displayTime = saleDateTime.ToLocalTime().ToShortTimeString();

    I hope this helps.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Chip
    Chip avatar
    14 posts
    Registered:
    25 Nov 2013
    01 Apr 2015
    Link to this post
    Thanks that fixed my issue. 
3 posts, 1 answered