Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

4 Answers 4

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

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);
share|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
add comment

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.

share|improve this answer
    
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
    
Oh, btw. You'll find the hotfix description here: support.microsoft.com/kb/2553031/en-us –  Robert Sep 27 '11 at 9:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.