Why is my time not displaying correct after upgrading to 8.1?

I upgraded one of our Sitecore solutions from Sitecore 6.2 (rev. 100507) to Sitecore 8.1 (rev. 151207). After the upgrade we noticed that the display of time on the website was slightly off. Instead of showing the GMT + 1 time it showed the UTC time (which is 2 hours off in our case). This caused that all newly created items (wheter it be reactions on news or news items itself) showed the wrong time. An item created on 11-04-2016 – 11:04 would be shown as 11-04-2016 – 09:04. As you might guess this wasn’t really what our customer was looking for and I haven’t stumpled upon any tips regarding this issue in the upgrade guide while upgrading the solution.

Now I have decompiled the Sitecore.Kernel and read some other posts regarding this issue I would like to share my solution to this problem. As per Sitecore documentation provided in the Sitecore.config file I looked for the Timezone I would like to use on msdn:

MSDN Article – Timezones

In my case I chose to use the “W. Europe Standard Time” so my settting in the sitecore.config file looked like this:

Now this seems all nice and ready to roll, but you aren’t done yet. If you are using for example “Sitecore.Statistics.Created” as your DateTime object and just format this date and .toString() it in any format with a time specification you will not yet see the correct time displayed. I therefor used the Sitecore.DateUtil.ToServerTime() method, which uses the ServerTimeZone setting we just specified to convert between the UTC and server time.

This results in the right date / time being shown on your website.

Hope you will find this article useful!

 

3 thoughts on “Why is my time not displaying correct after upgrading to 8.1?

  1. Thanks, we had the same issue (Date and Datetime fields, visually correct in Sitecore, but as raw value we noticed a -2 hour difference) resulting in strange behavior on our website.

  2. Well. That makes my NEW date fields shown right.
    Now the problem is with my old data, if I change the code to follow this then my older data will be shown wrong.
    Do you have any advice for this?
    btw I have about a thousand data in my previous sitecore.

Leave a Reply

Your email address will not be published. Required fields are marked *