//计算本月有哪些天是周六,周日
//本月开始日期
var
starMoth = DateTime.Now.AddDays(-DateTime.Now.Day + 1).Date;
//本月截至日期
var
stopMoth = starMoth.AddMonths(1).AddDays(-1).Date;
var
listSaturday =
new
List<DateTime>();
var
listSunday =
new
List<DateTime>();
var
temp = starMoth;
while
(temp <= stopMoth)
{
if
(temp.DayOfWeek == DayOfWeek.Saturday && temp <= stopMoth)
{
listSaturday.Add(temp.Date);
if
(temp.AddDays(1).Date <= stopMoth)
{
listSunday.Add(temp.AddDays(1));
}
temp = temp.AddDays(6);
}
else
{
temp = temp.AddDays(1);
}
}
Console.WriteLine(
"本月周六--"
);
listSaturday.ForEach(n => Console.WriteLine(n.Date));
Console.WriteLine(
"本月周日--"
);
listSunday.ForEach(n => Console.WriteLine(n.Date));
Console.ReadKey();