コード例 #1
0
        /// <summary>
        /// Regular.Match Group 2 DateTime
        /// </summary>
        /// <param name="m">Regular.Match</param>
        /// <param name="format">ISO8601DateTimeFormats</param>
        /// <returns>return DateTime</returns>
        internal static DateTime Match2DateTime(Match m, ISO8601DateTimeFormats format)
        {
            DateTime datetime = default(DateTime);

            switch (format)
            {
            case ISO8601DateTimeFormats.BasicCalendarDateAndLocalTime:
            case ISO8601DateTimeFormats.ExtendedCalendarDateAndLocalTime:
                datetime = new DateTime
                           (
                    Convert.ToInt32(m.Groups["year"].Value),
                    Convert.ToInt32(m.Groups["month"].Value),
                    Convert.ToInt32(m.Groups["day"].Value),
                    Convert.ToInt32(m.Groups["hour"].Value),
                    Convert.ToInt32(m.Groups["minute"].Value),
                    Convert.ToInt32(m.Groups["second"].Value)
                           );
                break;

            case ISO8601DateTimeFormats.BasicOrdinalDateAndUTCTime:
            case ISO8601DateTimeFormats.ExtendedOrdinalDateAndUTCTime:
                datetime = new DateTime
                           (
                    Convert.ToInt32(m.Groups["year"].Value),
                    1, 1,
                    Convert.ToInt32(m.Groups["hour"].Value),
                    Convert.ToInt32(m.Groups["minute"].Value),
                    Convert.ToInt32(m.Groups["second"].Value)
                           );
                datetime = datetime.AddDays(Convert.ToInt32(m.Groups["dayofyear"].Value) - 1);
                break;

            case ISO8601DateTimeFormats.BasicWeekDateAndLocalTime:
            case ISO8601DateTimeFormats.ExtendedWeekDateAndLocalTime:
                datetime = new DateTime
                           (
                    Convert.ToInt32(m.Groups["year"].Value),
                    1, 1,
                    Convert.ToInt32(m.Groups["hour"].Value),
                    Convert.ToInt32(m.Groups["minute"].Value),
                    Convert.ToInt32(m.Groups["second"].Value)
                           );
                Int32 dayofyear = ISO8601DateTimeHelper.GetDayOfYearByWeek(Convert.ToInt32(m.Groups["year"].Value), Convert.ToInt32(m.Groups["weekofyear"].Value), Convert.ToInt32(m.Groups["dayofweek"].Value));
                datetime = datetime.AddDays(dayofyear - 1);
                break;

            default:
                break;
            }
            return(datetime);
        }
コード例 #2
0
 /// <summary>
 /// 创建ISO8601DateTime对象
 /// </summary>
 /// <param name="datetime">日期和时间数据</param>
 /// <param name="format">格式化方式</param>
 public ISO8601DateTime(DateTime datetime, ISO8601DateTimeFormats format)
 {
     m_Value  = datetime;
     m_Format = format;
 }