コード例 #1
0
        /// <summary>
        /// 获取季度的第一天
        /// </summary>
        /// <param name="month">2018Q1</param>
        /// <returns></returns>
        public static DateTime ToQuarterFirstday(string quarter)
        {
            if (quarter == "")
            {
                quarter = ConvertDateTime.ToYearQuarterString();
            }

            int yearIndex    = ConvertObject.ToInt32(quarter.Substring(0, 4));
            int quarterIndex = ConvertObject.ToInt32(quarter.Substring(5, 1));

            switch (quarterIndex)
            {
            case 4:
                return(new DateTime(yearIndex, 10, 1));

            case 3:
                return(new DateTime(yearIndex, 7, 1));

            case 2:
                return(new DateTime(yearIndex, 4, 1));

            default:
                return(new DateTime(yearIndex, 1, 1));
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取当前日期所在的周日期
        /// </summary>
        /// <returns></returns>
        public static string[] GetWeekDays(DateTime date)
        {
            // int dateIndex = (int)date.DayOfWeek;
            int dateIndex = ((int)date.DayOfWeek) == 0 ? 7 : (int)date.DayOfWeek;

            String[] weekdays =
            {
                ConvertDateTime.ToDayString(date.AddDays(1 - dateIndex)),
                ConvertDateTime.ToDayString(date.AddDays(2 - dateIndex)),
                ConvertDateTime.ToDayString(date.AddDays(3 - dateIndex)),
                ConvertDateTime.ToDayString(date.AddDays(4 - dateIndex)),
                ConvertDateTime.ToDayString(date.AddDays(5 - dateIndex)),
                ConvertDateTime.ToDayString(date.AddDays(6 - dateIndex)),
                ConvertDateTime.ToDayString(date.AddDays(7 - dateIndex))
            };
            return(weekdays);
        }