如何使用DDay.iCal在iCal Feed中设置时区?

我正在使用DDay.iCal创建一个iCal feed。 它有效,但我无法弄清楚如何设置Feed的时区。 这是基本代码:

iCalendar iCal = new iCalendar(); // <-- Set the Timezone HERE to PST (Pacific Daylight Time) Event evt = iCal.Create(); evt.Start = new iCalDateTime(meeting.MeetDate); evt.End = evt.Start.AddHours(4); // 4 hour event evt.Description = "This meeting..."; evt.Summary = "Event Summary"; 

有任何想法吗?

在另一个答案中,作者没有提到示例6中这三行之上的行:

 // First load a file containing time zone information for North & South America IICalendar timeZones = iCalendar.LoadFromFile("America.ics")[0]; 

所以那不行。 一个选项是:

 iCalendar iCal = new iCalendar(); System.TimeZoneInfo timezoneinfo = System.TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"); iCalTimeZone timezone = iCalTimeZone.FromSystemTimeZone(timezoneinfo); iCal.AddTimeZone(timezone); 

或者只是添加本地时区:

 iCalendar iCal = new iCalendar(); iCal.AddLocalTimeZone(); 

要查找所有已注册的时区,请使用以下代码段 :

 ReadOnlyCollection zones = TimeZoneInfo.GetSystemTimeZones(); Console.WriteLine("The local system has the following {0} time zones", zones.Count); foreach (TimeZoneInfo zone in zones.OrderBy(z => z.Id)) Console.WriteLine(zone.Id); Console.ReadLine(); 

下载中的示例6是设置时区和事件的诸如此类的东西。 检查出。

相关专线:

 IICalendar iCal = new iCalendar(); iCal.AddChild(timeZones.GetTimeZone("America/New_York")); iCal.AddChild(timeZones.GetTimeZone("America/Denver")); // Set the event to start at 11:00 AM New York time on January 2, 2007. evt.Start = new iCalDateTime(2007, 1, 2, 11, 0, 0, "America/New_York", iCal)