DateTime picker time results shown 4 hours ahead

Posted by Community Admin on 04-Aug-2018 20:59

DateTime picker time results shown 4 hours ahead

All Replies

Posted by Community Admin on 25-Mar-2015 00:00

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? 

Posted by Community Admin on 30-Mar-2015 00:00

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
 

Posted by Community Admin on 01-Apr-2015 00:00

Thanks that fixed my issue. 

This thread is closed