【.net/.net core】获取当月日期字符串集合

/// 
        /// 获取当月日期集合,并返回yyyy-MM-dd日期格式字符串集合
        /// 
        /// 
        private List GetCurrentMouthDays() { 
            List days = new List();
            // 获取当前月份的第一天
            DateTime currentMonthFirstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            // 获取当前月份的最后一天
            DateTime currentMonthLastDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));

            // 创建一个日期列表,包含从当前月份第一天到最后一天的所有日期
            List dateList = new List();
            for (DateTime date = currentMonthFirstDay; date <= currentMonthLastDay; date = date.AddDays(1))
            {
                days.Add(date.ToString("yyyy-MM-dd"));
            }
            return days;
        }

你可能感兴趣的:(windows,服务器,linux)