VB.NET Windows窗体应用如何设置Outlook AppointmentItem的时区
实现方案
AppointmentItem的StartTimeZone和EndTimeZone属性需要传入Outlook.TimeZone类型对象,你可以直接通过Outlook应用实例的TimeZones集合获取指定ID的时区对象。
修正后完整代码
Dim TempApp As New Outlook.Application() Dim TempAppItem As Outlook.AppointmentItem = TempApp.CreateItem(Outlook.OlItemType.olAppointmentItem) TempAppItem.Subject = "Perform reminder action" TempAppItem.Body = "Reminder to perform" TempAppItem.Location = "No Location" ' 此处直接赋值悉尼当地时间即可,无需提前转UTC TempAppItem.Start = Convert.ToDateTime("22/11/2021 04:00:00 PM") TempAppItem.End = Convert.ToDateTime("22/11/2021 05:00:00 PM") ' 核心逻辑:获取澳东标准时间时区对象 TempAppItem.StartTimeZone = TempApp.TimeZones.Item("AUS Eastern Standard Time") TempAppItem.EndTimeZone = TempApp.TimeZones.Item("AUS Eastern Standard Time") TempAppItem.ReminderSet = True TempAppItem.ReminderMinutesBeforeStart = 0 TempAppItem.BusyStatus = Outlook.OlBusyStatus.olBusy TempAppItem.IsOnlineMeeting = False TempAppItem.Save() TempApp = Nothing TempAppItem = Nothing
注意事项
- 时区ID需要和Windows系统注册表中存储的标识完全匹配,
AUS Eastern Standard Time是悉尼、墨尔本所在时区的正确ID,自带夏令时自动切换逻辑 - 该属性仅支持Outlook 2010及更高版本,更低版本Outlook需要手动将悉尼时间转换为UTC后再赋值给
Start/End属性 - 不要提前将本地时间转换为UTC再赋值,Outlook会根据你设置的时区自动处理跨时区时间转换
内容的提问来源于stack exchange,提问作者dya
相关产品推荐
相关产品推荐

