Esempio n. 1
0
        /// <summary>
        /// 转换为ISO8601规范的日期字符串 默认格式YYYYMMDD
        /// </summary>
        /// <returns>返回ISO8601规范的日期字符串</returns>
        public override string ToString()
        {
            Int32 no = (Int32)Format;

            switch (Format)
            {
            case ISO8601DateFormats.BasicCalendarDate:
                return(String.Format(MyRegularExpressions[no][2], Value.Year, Value.Month, Value.Day));

            case ISO8601DateFormats.ExtendedCalendarDate:
                return(String.Format(MyRegularExpressions[no][2], Value.Year, Value.Month, Value.Day));

            case ISO8601DateFormats.BasicOrdinalDate:
                return(String.Format(MyRegularExpressions[no][2], Value.Year, Value.DayOfYear));

            case ISO8601DateFormats.ExtendedOrdinalDate:
                return(String.Format(MyRegularExpressions[no][2], Value.Year, Value.DayOfYear));

            case ISO8601DateFormats.BasicWeekDate:
                return(String.Format(MyRegularExpressions[no][2], Value.Year, ISO8601DateTimeHelper.GetWeekOfYear(Value), ISO8601DateTimeHelper.GetDayOfWeek(Value.DayOfWeek)));

            case ISO8601DateFormats.ExtendedWeekDate:
                return(String.Format(MyRegularExpressions[no][2], Value.Year, ISO8601DateTimeHelper.GetWeekOfYear(Value), ISO8601DateTimeHelper.GetDayOfWeek(Value.DayOfWeek)));

            default:
                return("");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Regular.Match Group 2 DateTime
        /// </summary>
        /// <param name="m">Regular.Match</param>
        /// <param name="format">ISO8601DateFormats</param>
        /// <returns>return DateTime</returns>
        internal static DateTime Match2DateTime(Match m, ISO8601DateFormats format)
        {
            DateTime datetime = default(DateTime);

            switch (format)
            {
            case ISO8601DateFormats.BasicCalendarDate:
            case ISO8601DateFormats.ExtendedCalendarDate:
                datetime = new DateTime(Convert.ToInt32(m.Groups["year"].Value), Convert.ToInt32(m.Groups["month"].Value), Convert.ToInt32(m.Groups["day"].Value));
                break;

            case ISO8601DateFormats.BasicOrdinalDate:
            case ISO8601DateFormats.ExtendedOrdinalDate:
                datetime = new DateTime(Convert.ToInt32(m.Groups["year"].Value), 1, 1);
                datetime = datetime.AddDays(Convert.ToInt32(m.Groups["dayofyear"].Value) - 1);
                break;

            case ISO8601DateFormats.BasicWeekDate:
            case ISO8601DateFormats.ExtendedWeekDate:
                datetime = new DateTime(Convert.ToInt32(m.Groups["year"].Value), 1, 1);
                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);
        }