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:
In my case I chose to use the “W. Europe Standard Time” so my settting in the sitecore.config file looked like this:
<!-- SERVER TIME ZONE
This setting specifies the server time zone that is used by the server to convert UTC time to local time, for example "GMT Standard Time".
The value must be parsable to a valid Time Zone ID. See http://msdn.microsoft.com/en-us/library/gg154758.aspx
If blank, Sitecore uses the operating system time zone.
Default value: "" (use the operating system time zone)
<setting name="ServerTimeZone" value="W. Europe Standard Time" />
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.
DateTime serverTime = Sitecore.DateUtil.ToServerTime(item.Statistics.Created);
string dateCreated = serverTime.ToString("dd-MM-yyyy, HH:mm");
This results in the right date / time being shown on your website.
Hope you will find this article useful!