It seems that the datetime value which is entered into a DateTimeField is always stored as UTC no matter what timezone is configured for the current user.

Only the output on the page is displayed in the correct timezone format. So for me (UTC+3) the time displayed on the page is always +3 hours form the time that I've entered into the field. How can I avoid that?

For example if I enter 2011/01/01 5PM into the DateTimeField and publish the page the displayed date is 2011/01/01 8PM.

  • It is a problem of timezone difference.your server time is utc+3 then your machine. – sachin Jul 21 '15 at 7:22

For SharePoint with users from different timezones the only working solution is to store all DateTimes in UTC format. This is the only time (zone) that's not affected by Daylight saving changes and other stuff.

This behavior is by design and it cannot be changed, however there are methods that help you display correct time. Check article Converting Date and Time Values as your starting point.

|improve this answer|||||

Problem is in method "onBeforeRendering", right after changing timezone of date, there is an used object named MutableDateTime, which kills all timezone settings. So this object returns correct time, but displays incorrect one

|improve this answer|||||
  • MutableDateTime is a column in SharePoint calendar.? – Dilip Kumar Yadav Dec 28 '16 at 9:51

As Toni says when setting a date/time programatically you should use UTC.

The time zone that will be used for the display is set at the Web's level (regional setttings).

To convert between the web sites time zone to UTC you should get the webs time zone from the regional settings property and use the LocalTimeToUTC method

So something like

SPTimeZone timeZone = SPContent.Current.Web.RegionalSettings.TimeZone;
listItem[fieldName] = timeZone.LocalTimeToUTC(localTime);
|improve this answer|||||
  • I don't set the time programatically. The time is set per DateTimeField control in the page layout. So do I have to write my own control to let the user type in the time in his time zone and the control converts and saves it as UTC? By now the users input is plain UTC and that's confusing. – user2764 Mar 29 '11 at 13:28
  • No - if you're doing this in the normal web UI then it should all be taken care of for you. – Ryan Mar 29 '11 at 13:37
  • That's not the case and that's why this question was started :) The time the user entered is different from the time that is displayed on the page after the page was published. – user2764 Mar 29 '11 at 14:11
  • I getcha - thats how its supposed to work thats all I am saying. BTW - I think you need to clarify your question a little, its really not clear what you're saying. e.g. you said "Only the output on the page is displayed in the correct timezone format" - but you're now saying that it doesn't. Confused am I! Not for the first time where SharePoint is concerned ;) – Ryan Mar 29 '11 at 16:27

It seems to be a SharePoint Bug. Normally the User Controls convert the time to the current user's time zone in the rendering process. This does not work well in DateTimeFields. We have an open ticket with MS regarding this problem. I will post the results as soon as we have a reliable answer.

|improve this answer|||||
  • 1
    Good news! Our support ticket has been answered and the August Commulated Update includes a fix to this problem. support.microsoft.com/kb/2553048 --> Description of the SharePoint Server 2010 cumulative update package (SharePoint server-package): August 30, 2011 – Robert Sep 27 '11 at 9:06
  • 1
    Oh, btw. You'll find the hotfix description here: support.microsoft.com/kb/2553031/en-us – Robert Sep 27 '11 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy