I need a real time zones guru help!
My goal is to write a tool (in .Net) that would show datetime values from SharePoint DB with a selected timezone offset. I’ve found that SharePoint keeps datetime values as UTC in its DB. It shows them with a timezone offset, that is stored as int (0 .. ~50). A little investigation showed the int value is CDO code. There is no way to convert a CDO code except manual mapping, written by me, based on different sources.
Now, I have a failed unit test with the following values: CDO is 34, time in UTC is 2011-05-26 14:55:00. From GUI side, the timezone looks like ‘(GMT-05:00) Indiana (East)’. In my map 34 corresponds to “US Eastern Standard Time” timezone id.
var id = "US Eastern Standard Time";
var zone = TimeZoneInfo.FindSystemTimeZoneById(id);
Console.WriteLine(zone);
Console.WriteLine(zone.StandardName);
The result is:
(GMT-05:00) Indiana (East)
US Eastern Standard Time
Looks like it’s OK, both are ‘Indiana (East)’. Now, I use the zone to convert the value:
var dateTime = new DateTime(2011, 05, 26, 14, 55, 00);
var converted = TimeZoneInfo.ConvertTimeFromUtc(dateTime, zone);
Console.WriteLine(converted);
And the result is 26.05.2011 10:55:00. But SharePoint shows it as 26.05.2011 09:55:00! That’s why my unit test has been failed. I’ve discovered timezoneconverter.com online tool. It has no way to set a timezone as CDO or .Net timezone id, so I had chosen ‘America/Indiana/Indianapolis’:
14:55:00 Thursday May 26, 2011 in UTC converts to
10:55:00 Thursday May 26, 2011 in America/Indiana/Indianapolis
My converter has the same result. Then I chose ‘America/Indiana/Knox’:
14:55:00 Thursday May 26, 2011 in UTC converts to
09:55:00 Thursday May 26, 2011 in America/Indiana/Knox
Google Maps service shows Knox is located more to the west, so it looks normal.
Definitely, SharePoint uses the last timezone. But HOW? Is there an additional flag to CDO code that helps to find a more appropriate Knox timezone? What is the zone? What is its id? I’m living outside the US, so I’m almost gone crazy with the zones.
Thank you,
If you face a problem that looks like mine (a timezone that seems working incorrectly), the answer is: TRY ANOTHER TIMEZONE. For instance, I’ve found that “SA Pacific Standard Time” is what I need.