2

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?

1

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.

0
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));
  • issue with DST. Example: UTC +1 for Paris is for winter, in summer we have UTC +2. – Mathieu Chateau May 5 '18 at 11:31

Your Answer

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

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