2010-09-23 32 views
5

Tôi đang tạo nguồn cấp dữ liệu iCal bằng cách sử dụng DDay.iCal. Nó hoạt động, nhưng tôi không thể tìm ra cách đặt múi giờ cho nguồn cấp dữ liệu. Đây là mã cơ bản:Làm cách nào để đặt múi giờ trong nguồn cấp dữ liệu iCal bằng DDay.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"; 

Bất kỳ ý tưởng nào?

Trả lời

3

Ví dụ6 trong phần tải xuống được đặt múi giờ và không cho sự kiện. Kiểm tra xem.

dòng liên quan:

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

Trong câu trả lời khác, tác giả không đề cập đến những dòng trên những ba dòng đó là trong ví dụ 6:

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

Vì vậy, đó sẽ không hoạt động. Một lựa chọn sẽ là:

iCalendar iCal = new iCalendar(); 

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

Hoặc chỉ cần thêm múi giờ địa phương:

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

Để tìm tất cả các múi giờ đăng ký, sử dụng 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(); 
Các vấn đề liên quan