用于工作:
1.取本月第一天就是1号
2.取下月第一天再减去一天 就是本月最后一天
3.从月头遍历至月末,判断周几
代码如下:
#region 提取本月周六日 DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); DateTime end = start.AddMonths(1).AddDays(-1); DateTime temp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); for (int i = start.Day; i <= end.Day; i++) { if (temp.DayOfWeek == DayOfWeek.Sunday || temp.DayOfWeek == DayOfWeek.Saturday) { Console.WriteLine(temp.ToString("yyyy-MM-dd HH:mm:ss")); } temp = temp.AddDays(1); } #endregion