azure - 在 UTC 时区的 EWS 中创建的定期约会在夏令时更改后移动 1 小时

标签 azure exchange-server exchangewebservices office365

我有一个使用 C# 使用连接到 Office 365 Exchange 的 Exchange Web Services EWS 2.0 创建的定期约会。该约会正确显示在我的 Outlook 夏季议程中。但 10 月 26 日(冬季)之后,预约时间提前了一个小时(提前)。

显然这与夏令时有关,但我不知道这是如何工作的。我想说的是,约会中设置的时间和 UTC 中设置的时间应该由 Outlook 自动转换,以在我的正确时区(UTC+1 阿姆斯特丹)和 DST 中显示。但它在 DST 上失败。

正如您在 co 中看到的,我用来创建约会的代码的相关部分:

创建服务:

ExchangeService _Service = new ExchangeService ExchangeVersion.Exchange2013_SP1,TimeZoneInfo.Utc);

设置时区:

appointment.StartTimeZone = TimeZoneInfo.Utc;
appointment.EndTimeZone = TimeZoneInfo.Utc;

但是当夏令时改变时,预约仍然会改变。

如何使用 EWS 创建一个全年在 Outlook 中正确显示的定期约会?

编辑: 感谢 venkat-ayyadevara-msft 和 pjneary 解决了这个问题。

西欧与UTC的实际时差夏季为2小时,冬季仅为1小时。因此,如果您以 UTC 时间设置约会,则 UTC 时间的开始时间始终相同。但由于西欧夏季相距 2 小时,冬季仅相距 1 小时,因此西欧 TZ 的预约时间会调整一小时。

解决方案:确定开始时间必须固定在哪个 TZ,并将该时区设置为您的约会。如果从您的服务或数据库检索的时间不在该时区,您需要将其转换为约会的时区。

最佳答案

这里是一个代码示例,它应该使用 TimeZoneInfo.ConvertTimeFromUtc() 满足您的要求,即从 SQL 数据库读取 UTC 时间并将其转换为阿姆斯特丹时间,考虑夏令时。

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1, TimeZoneInfo.Utc);

        // Create recurring calendar item
        Appointment appointment = new Appointment(service);
        appointment.Subject = "Some subject";
        DateTime start = new DateTime(2014, 10, 14, 16, 0, 0);
        appointment.Start = TimeZoneInfo.ConvertTimeFromUtc(start, TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
        appointment.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"); 
        DateTime end = new DateTime(2014, 10, 14, 17, 0, 0);
        appointment.End = TimeZoneInfo.ConvertTimeFromUtc(end, TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
        appointment.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
        appointment.Location = "Some location";
        DayOfTheWeek[] days = new DayOfTheWeek[] { DayOfTheWeek.Saturday };
        appointment.Recurrence = new Recurrence.WeeklyPattern(appointment.Start.Date, 1, days);
        appointment.Recurrence.StartDate = appointment.Start.Date;
        appointment.Recurrence.NumberOfOccurrences = 20;

        // Save appointment
        appointment.Save(SendInvitationsMode.SendToNone);

希望这对您有用。另请参阅here用于 EWS 托管 API 使用的时区定义。

如果您有任何疑问或需要更多信息,请告诉我。

谢谢

文卡特

关于azure - 在 UTC 时区的 EWS 中创建的定期约会在夏令时更改后移动 1 小时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26292930/

相关文章:

perl - MS Exchange POP3 UIDL 命令提供的 UID 真的是唯一的吗?

c# - 使用 MIP SDK 从 MS 365 个人帐户解密加密的 Office 365 电子邮件

Azure map 和多边形

azure - Microsoft Azure 信息保护中是否有一次性密码选项?

azure - 禁用 Azure 云服务负载均衡器中的关联性(Web/辅助角色)

c# - 为什么我的 Exchange ResolveNames 搜索只返回 100 行?

powershell - 将标签应用到资源模板文件中的 Azure 资源组

web-services - Exchange Web 服务 : ExtendedPropertyDefinition IDs defined? 在哪里

powershell - 激活交换PowerShell命令