DateTime picker time results shown 4 hours ahead
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?
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();
Thanks that fixed my issue.