我们正在使用Graph Api获取和设置日历事件。
我们调用GetSchedule并使用WorkingHours.TimeZone.Name尝试获取TimeZoneInfo。
TimeZoneInfo.FindSystemTimeZoneById(workingHours.TimeZone.Name);
对于大多数在Outlook中设置的时区(例如东部标准时间),时区名称是正确的,并且一切正常。
但是,如果将Outlook设置为类似于亚利桑那州时区(在Outlook中设置时区时可以选择),则会引发错误消息:
The time zone ID 'Customized Time Zone' was not found on the local computer.
因此,我们尝试通过使用偏差/偏移量创建自定义时区来解决此问题
try
{
return TimeZoneInfo.FindSystemTimeZoneById(workingHours.TimeZone.Name);
}
catch (Exception ex)
{
var customTimeZone = workingHours.TimeZone as CustomTimeZone;
return TimeZoneInfo.CreateCustomTimeZone("Customized Time Zone", TimeSpan.FromMinutes(Convert.ToDouble(customTimeZone.Bias)), "Customized Time Zone", "Customized Time Zone");
}
这可以为呼叫创建新的时区信息对象,但是当我们使用该时区安排事件时,会抛出错误:
Code: TimeZoneNotSupportedException
Message: A valid TimeZone value must be specified. The following TimeZone value is not supported: 'Customized Time Zone'.
为什么会为亚利桑那州的时间表提供自定义时区?我们如何安排具有自定义时区的事件?