/// <summary>
/// 获取当月日期集合,并返回yyyy-MM-dd日期格式字符串集合
/// </summary>
/// <returns></returns>
private List<string> GetCurrentMouthDays() {
List<string> days = new List<string>();
// 获取当前月份的第一天
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<DateTime> dateList = new List<DateTime>();
for (DateTime date = currentMonthFirstDay; date <= currentMonthLastDay; date = date.AddDays(1))
{
days.Add(date.ToString("yyyy-MM-dd"));
}
return days;
}
【.net/.net core】获取当月日期字符串集合
于 2024-02-01 17:28:28 首次发布