通过EWS更新的约会显示UTC而不是本地TZ

时间:2013-08-21 12:02:54

标签: exchangewebservices

我已经针对此问题进行了研究,但无法找到解决方案。

SO帖子TimeZone change to UTC while updating the Appointment提到了同样的问题,但我已经测试了解决方案,但它没有用。

这是错的:

enter image description here

有没有人有解决方案?时间正确地反映在Outlook,电子邮件等上。只是所显示的文字误导人并造成混淆。

*请注意,可以将以下代码复制并粘贴到控制台应用程序中进行测试。

var timezone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");

var service = new ExchangeService(ExchangeVersion.Exchange2013, timezone);
service.Credentials = new NetworkCredential("myemail@mydomain.com", "mypassword");
service.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx");

var meeting1 = new Appointment(service);
meeting1.Subject = "Test Meeting";
meeting1.Body = "Test body";
meeting1.Start = new DateTime(2013, 8, 22, 9, 0, 0); //my default time is GMT+8
meeting1.End = meeting1.Start.AddHours(2);
meeting1.Location = "Conf Room";
meeting1.RequiredAttendees.Add("someone@outlook.com");

meeting1.Save(SendInvitationsMode.SendToAllAndSaveCopy);

Console.WriteLine("1st invite sent");

var id = meeting1.Id.ToString();


System.Threading.Thread.Sleep(5000); //break for a while...

//re-fetch the appointment
var meeting2 = Appointment.Bind(service, new ItemId(id),
        new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start,                                          
              AppointmentSchema.End, AppointmentSchema.StartTimeZone,  
              AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone));

Console.WriteLine( meeting2.StartTimeZone ); //shows Tokyo Standard Time correctly.

meeting2.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
meeting2.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
meeting2.Start = new DateTime(2013,8,23, 9,0,0, DateTimeKind.Unspecified);
meeting2.End = meeting2.Start.AddHours(2);
meeting2.Subject = "Updated Test Meeting";
meeting2.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);


meeting2.Load(new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Start,
    AppointmentSchema.End, AppointmentSchema.StartTimeZone,  
            AppointmentSchema.EndTimeZone, AppointmentSchema.TimeZone, 
            AppointmentSchema.Body, AppointmentSchema.NormalizedBody,AppointmentSchema.TextBody));


Console.WriteLine( meeting2.StartTimeZone ); //shows Tokyo Standard Time correctly. 

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,因为我们正在使用ExchangeVersion.Exchange2010_SP2,但我设法绕过这个问题:

appointment.Save(SendInvitationsMode.SendToNone);
// to fix the issue of updating appointment sets timezone to UTC, we use ExchangeVersion.Exchange2007_SP1
service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials(Account, Password);
service.Url = new Uri(url);
service.Timeout = 600000;