|
最近有项目用到EWS API的发起会议,时区一起无法找到正确解决办法,如果时区不对,那么会议时间和UTC时间会冲突的。显示如下错误:
经过MSDN资料查找,原来可以设置时区的。
TimeZoneInfo.FindSystemTimeZoneById("China Standard Time")表示北京时间
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");表示美国中部时间
依次类推
代码如下:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1, TimeZoneInfo.FindSystemTimeZoneById("China Standard Time"));
service.Credentials = new NetworkCredential("XXXX", "XXXX", "XXX.com");
service.Url = new Uri("https://XXX.XXX.com/EWS/Exchange.asmx");
//实例化一个Appointment
Appointment appointment = new Appointment(service);
//约会主题
appointment.Subject = "测试UTC,设置了北京时间?";
//约会内容
appointment.Body = "测试,设置了北京时间";
//约会开始时间2010-6-1 12:30:00
appointment.Start = new DateTime(2012, 11, 29, 08, 30, 0);
//约会结束
appointment.End = appointment.Start.AddDays(5);
//约会的位置
appointment.Location="216会议室";
//添加与会者
appointment.RequiredAttendees.Add("XXX@XXXX.com");
// 从2010-6-1 12:30:00开始每周举行一次
//appointment.Recurrence = new Recurrence.WeeklyPattern(appointment.Start,1,DayOfWeek.Saturday);
//可以设置发送通知的方式,如:
//Appointment.Save(SendInvitationsMode.SendOnlyToAll)
appointment.Save();
MessageBox.Show("ok");
正确效果图如下:
|
|