Beispiel #1
0
 public static int Second(DateTime TimeValue)
 {
     return(CurrentCalendar.GetSecond(TimeValue));
 }
Beispiel #2
0
        public static int DatePart(DateInterval Interval,
                                   DateTime DateValue,
                                   [Optional, DefaultParameterValue(FirstDayOfWeek.Sunday)]
                                   FirstDayOfWeek FirstDayOfWeekValue,
                                   [Optional, DefaultParameterValue(FirstWeekOfYear.Jan1)]
                                   FirstWeekOfYear FirstWeekOfYearValue)
        {
            DayOfWeek        firstDayOfWeek;
            CalendarWeekRule calendarWeekRule = 0;

            switch (Interval)
            {
            case DateInterval.Year:
                return(CurrentCalendar.GetYear(DateValue));

            case DateInterval.Quarter:
                return(((DateValue.Month - 1) / 3) + 1);

            case DateInterval.Month:
                return(CurrentCalendar.GetMonth(DateValue));

            case DateInterval.DayOfYear:
                return(CurrentCalendar.GetDayOfYear(DateValue));

            case DateInterval.Day:
                return(CurrentCalendar.GetDayOfMonth(DateValue));

            case DateInterval.WeekOfYear:
                if (FirstDayOfWeekValue != FirstDayOfWeek.System)
                {
                    firstDayOfWeek = (DayOfWeek)(FirstDayOfWeekValue - 1);
                    break;
                }
                firstDayOfWeek = Utils.GetCultureInfo().DateTimeFormat.FirstDayOfWeek;
                break;

            case DateInterval.Weekday:
                return(Weekday(DateValue, FirstDayOfWeekValue));

            case DateInterval.Hour:
                return(CurrentCalendar.GetHour(DateValue));

            case DateInterval.Minute:
                return(CurrentCalendar.GetMinute(DateValue));

            case DateInterval.Second:
                return(CurrentCalendar.GetSecond(DateValue));

            default:
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Interval" }));
            }
            switch (FirstWeekOfYearValue)
            {
            case FirstWeekOfYear.System:
                calendarWeekRule = Utils.GetCultureInfo().DateTimeFormat.CalendarWeekRule;
                break;

            case FirstWeekOfYear.Jan1:
                calendarWeekRule = CalendarWeekRule.FirstDay;
                break;

            case FirstWeekOfYear.FirstFourDays:
                calendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
                break;

            case FirstWeekOfYear.FirstFullWeek:
                calendarWeekRule = CalendarWeekRule.FirstFullWeek;
                break;
            }
            return(CurrentCalendar.GetWeekOfYear(DateValue, calendarWeekRule, firstDayOfWeek));
        }