【问题标题】:How to create a Meeting Request using C# TimeZoneInfo class with the 4.6.5 Time Zone Component VTIMEZONE如何使用带有 4.6.5 时区组件 VTIMEZONE 的 C# TimeZoneInfo 类创建会议请求
【发布时间】:2012-05-06 08:46:00
【问题描述】:

美好的一天!

我正在尝试更新一些预先存在的代码,这些代码使用 4.6.5 时区组件 VTIMEZONE 根据用户在 asp.net 网站上的表单中的输入创建会议请求。我正在进行的更新是删除作为枚举列出的静态时区列表,并用 TimeZoneInfo GetSystemTimeZones 方法替换它们。问题在于 VTIMEZONE 的设置方式具有静态值。我想知道如何最好地解决这个问题,并欢迎任何建议。

这是一个sn-p的代码:

        private const string vTimeZoneTemplate = @"
BEGIN:VTIMEZONE
TZID:Pacific
BEGIN:STANDARD
DTSTART:20071104T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
TZNAME:PST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20070311T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
TZNAME:PDT
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:Eastern
BEGIN:STANDARD
DTSTART:20071104T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20070311T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
END:DAYLIGHT
END:VTIMEZONE";

最终目标是为所选时区设置会议请求的开始时间。即,我选择在伊斯坦布尔 (UTC+02:00) 下午 4:00 开始的 2 小时会议,它将在伊斯坦布尔时间(目前是土耳其标准时间)的下午 4:00 到下午 6:00 创建一个会议请求。

如果有帮助,我正在使用 TimeZoneInfo:

 if (!IsPostBack)
    {
        System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> TimeZoneList = TimeZoneInfo.GetSystemTimeZones();
        this.ddlTimezones.DataSource = TimeZoneList;
        this.ddlTimezones.DataTextField = "DisplayName";
        this.ddlTimezones.DataValueField = "Id";
        this.ddlTimezones.DataBind();
    }

【问题讨论】:

    标签: c# asp.net timezone timezone-offset


    【解决方案1】:

    这个:

    //This string is used for timezones that observe DST
    //RRULE:FREQ=YEARLY;BYDAY=[Week of Month][Day];BYMONTH=[Month]
        private const string vTimeZoneTemplate1 = @"
    BEGIN:VTIMEZONE
    TZID:{0}
    BEGIN:DAYLIGHT
    DTSTART:{1}
    RRULE:FREQ=YEARLY;BYDAY={9}{11};BYMONTH={7}
    TZOFFSETFROM:{2}
    TZOFFSETTO:{3}
    TZNAME:{4}
    END:DAYLIGHT
    BEGIN:STANDARD
    DTSTART:{6}
    RRULE:FREQ=YEARLY;BYDAY={10}{12};BYMONTH={8}
    TZOFFSETFROM:{3}
    TZOFFSETTO:{2}
    TZNAME:{5}
    END:STANDARD
    END:VTIMEZONE";
    
    //This string is used for timezones that do not observe DST; however, DAYLIGHT and STANDARD are required.
    //Therefore used static dates and made no change to the UTCOffset
        private const string vTimeZoneTemplate2 = @"
    BEGIN:VTIMEZONE
    TZID:{0}
    BEGIN:DAYLIGHT
    DTSTART:20070311T020000
    RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
    TZOFFSETFROM:{1}
    TZOFFSETTO:{1}
    TZNAME:{2}
    END:DAYLIGHT
    BEGIN:STANDARD
    DTSTART:20071104T020000
    RRULE:RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
    TZOFFSETFROM:{1}
    TZOFFSETTO:{1}
    TZNAME:{2}
    END:STANDARD
    END:VTIMEZONE";
    

    还有这个:

             /**
             * get the adjustment rules for the selected timezone.
             * the adjustment rule is the Daylight Savings adjustment by default.
             * using the i to note the most recent rule.
             * DateStart and .DateEnd designate the begin and end of the rule.
             * DaylightTransitionStart and End designate the begin and end date of DST.
             * DayLightDelta is the difference between base UTC and the offset by DS, add to get DS value from Base.
             **/
            if (timezone.SupportsDaylightSavingTime)
            {
                TimeZoneInfo.AdjustmentRule[] adjustments = timezone.GetAdjustmentRules();
                int i = adjustments.Length - 1;
    
                string body = string.Format(vTimeZoneTemplate1
                    , timezone.Id
                    , adjustments[i].DateStart.ToString(DateTimeFormat)
                    , timezone.BaseUtcOffset
                    , adjustments[i].DaylightDelta.Add(timezone.BaseUtcOffset)
                    , timezone.DaylightName
                    , timezone.StandardName
                    , adjustments[i].DateEnd.ToString(DateTimeFormat)
                    , adjustments[i].DaylightTransitionStart.Month.ToString("MM")
                    , adjustments[i].DaylightTransitionEnd.Month.ToString("MM")
                    , adjustments[i].DaylightTransitionStart.Week.ToString()
                    , adjustments[i].DaylightTransitionEnd.Week.ToString()
                    , adjustments[i].DaylightTransitionStart.IsFixedDateRule
                        ? adjustments[i].DaylightTransitionStart.Day.ToString().Substring(0, 2) 
                        : adjustments[i].DaylightTransitionStart.DayOfWeek.ToString().Substring(0, 2)
                    , adjustments[i].DaylightTransitionEnd.IsFixedDateRule
                        ? adjustments[i].DaylightTransitionEnd.Day.ToString().Substring(0, 2)
                        : adjustments[i].DaylightTransitionEnd.DayOfWeek.ToString().Substring(0, 2)) +
                    string.Format(vEventTemplate
                        , timezone.Id
                        , startDate
                        , endDate
                        , summary
                        , description
                        , Guid.NewGuid().ToString()
                        , sequence
                        , DateTime.Now.ToString(DateTimeFormat)
                        , vCalAttendees.ToString()
                        , organizer.FullName
                        , organizer.Email
                        , location
                        , string.IsNullOrEmpty(this.DescriptionHtml) ? string.Empty : string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", Email.WrapHTMLBody(this.DescriptionHtml, false, false))) +
                    (enableReminder ? vAlarmTemplate : string.Empty);
    
                return string.Format(baseVCalTemplate, body);
            }
            else
            {
                string body = string.Format(vTimeZoneTemplate2
                    , timezone.Id
                    , timezone.BaseUtcOffset
                    , timezone.DisplayName) +
                    string.Format(vEventTemplate
                        , timezone.Id
                        , startDate
                        , endDate
                        , summary
                        , description
                        , Guid.NewGuid().ToString()
                        , sequence
                        , DateTime.Now.ToString(DateTimeFormat)
                        , vCalAttendees.ToString()
                        , organizer.FullName
                        , organizer.Email
                        , location
                        , string.IsNullOrEmpty(this.DescriptionHtml) ? string.Empty : string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", Email.WrapHTMLBody(this.DescriptionHtml, false, false))) +
                    (enableReminder ? vAlarmTemplate : string.Empty);
    
                return string.Format(baseVCalTemplate, body);
            }
        }
    

    为我工作。所以,我希望它也可以帮助其他人。 :)

    【讨论】:

      【解决方案2】:

      对于当前信息 String.Format 和 TimeZoneInfo 的字段,如BaseUtcOffset 应该有助于一些属性

      vTimeZoneTemplate =   String.Format(
           "BEGIN:VTIMEZONE\n...{0}{1}...",
            tz.BaseUtcOffset.Hours, tz.BaseUtcOffset.Minutes);
      

      但我不确定您是否可以使用 TimeZoneInfo 收集足够的信息来构建完整的 VTIMEZONE 结构。

      【讨论】:

      • 因为我不知道你能不能 - 我自己从来没有做过/看起来不够深入。
      猜你喜欢
      • 2012-10-31
      • 2012-03-13
      • 2023-03-18
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多