views:

231

answers:

1

I have a document library that I am accessing programmatically as an SPList. When I use the LastItemModifiedDate property of the list, the DateTime returned is {1/7/2010 1:37:41 AM} but when I browse to the document library (with my web browser) I can see the most recent modified date is 7/01/2010 12:37 PM (this is the correct local time when I edited the file).

This looks to me like a timezone issue, but I'm not sure where LastItemModifiedDate is getting its settings from.

What do I need to change so that LastItemModifiedDate and the time appearing in my browser agree?

+2  A: 

Check Site Settings => Regional Settings => Time Zone. If you convert your Local time to GMT using the given offset, to they match?

If yes, then you can try getting the Time Zone for the Site using SPWeb.RegionalSettings.TimeZone and then either use LocalTimeToUTC or UTCToLocalTime to convert between the timezone of the site and UTC (Note that on SharePoint, you could give each Site it's own regional settings and TimeZone).

Edit: Just double checked, SPList.LastItemModifiedDate is always UTC. I'll leave a comment on MSDN.

Michael Stum
Thanks Michael.
kristian
I believe that every date is stored as UTC in SharePoint internally. This is also why they need to patch SharePoint when DST changes happen (as this one here: http://blogs.msdn.com/sharepoint/archive/2007/09/19/important-hotfixes-for-upcoming-daylight-savings-time-dst-change.aspx)
naivists
So do I. As every site in SharePoint can have it's own Time Zone and as you can move content between sites, I highly doubt that SharePoint always recalculates the date, but rather store it in UTC and then internally uses UTCToLocalTime (or whatever that uses internally) to display the dates.
Michael Stum