2010-09-23 80 views
5

我使用DDay.iCal創建iCal訂閱源。它的工作原理,但我不知道如何設置飼料的時區。這裏的基本代碼:如何使用DDay.iCal在iCal供稿中設置時區?

iCalendar iCal = new iCalendar(); 

// <-- Set the Timezone HERE to PST (Pacific Daylight Time) 

Event evt = iCal.Create<Event>(); 

evt.Start = new iCalDateTime(meeting.MeetDate); 
evt.End = evt.Start.AddHours(4); // 4 hour event 
evt.Description = "This meeting..."; 
evt.Summary = "Event Summary"; 

任何想法?

回答

3

下載中的示例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 A.M. New York time on January 2, 2007. 
evt.Start = new iCalDateTime(2007, 1, 2, 11, 0, 0, "America/New_York", iCal) 
8

在對方的回答是,作者沒有提那些三行這就是例子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(); 

查找所有已註冊的時區,使用this snippet

ReadOnlyCollection<TimeZoneInfo> 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();