1

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

SO post TimeZone change to UTC while update the Appointment提到了同样的问题,但我已经测试了解决方案并且它不起作用。

这是错误的:

在此处输入图像描述

有没有人有办法解决吗?时间正确反映在 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. 
4

1 回答 1

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;
于 2015-04-01T17:41:24.300 回答