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

I am working with the Exchange Managed API on SharePoint and in order to correctly get date/time information from the Exchange Managed API I need to pass it a TimeZoneInfo object when initializing the ExchangeService object. I would like to get the time zone in this order: 1) by the user profile, if null then 2) the default time zone of the current web application, if null then 3) the time zone of the server.

I am able to get the time zone of the server with TimeZoneInfo.Local, however the time zone of the user profile and the web application return as an SPTimeZone object.

The SPTimeZone object also has an SPTimeZoneInformation property (SPTimeZone.Information).

Does anyone have a method where I can convert an SPTimeZone (or SPTimeZoneInformation) object into a TimeZoneInfo object?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

So far the best method I have found is to pass Exchange the UTC TimeZoneInfo with "TimeZoneInfo.Utc". Once I have the DateTime objects on the SharePoint side (returned from Exchange in UTC time) I can then use the SPTimeZone.UTCToLocalTime(utcTime) method to convert the UTC DateTime to Local DateTime.

I would still like a way to tell Exchange what time zone to use by converting from SPTimeZone to TimeZoneInfo.

share|improve this answer
DateTime startDate = DateTime.Parse(DateTime.Now);

string utcDiff = web.RegionalSettings.TimeZone.Description;
utcDiff = utcDiff.Substring(utcDiff.IndexOf("UTC") + 3, 6).Replace(':', '.');
startDate = startDate.ToUniversalTime().AddHours(Double.Parse(utcDiff, System.Globalization.NumberStyles.Any));
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.