【问题标题】:How do I set the timezone in an iCal feed using DDay.iCal?如何使用 DDay.iCal 在 iCal 源中设置时区?
【发布时间】:2010-09-23 00:11:06
【问题描述】:

我正在使用 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";

有什么想法吗?

【问题讨论】:

    标签: c# asp.net icalendar


    【解决方案1】:

    在另一个答案中,作者没有提到示例 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();
    

    【讨论】:

      【解决方案2】:

      下载中的示例 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)
      

      【讨论】:

        猜你喜欢
        • 2014-07-19
        • 1970-01-01
        • 2017-03-17
        • 2016-09-12
        • 1970-01-01
        • 1970-01-01
        • 2011-12-05
        • 2018-08-30
        • 2014-11-21
        相关资源
        最近更新 更多