日期:2014-05-16 浏览次数:20831 次
DateTime d1 = new DateTime(2014, 2, 1);
DateTime d2 = new DateTime(2014, 3, 28);
DateTime TempD = d1;
List<string> L = new List<string>();
for(int i = 0 ;i<= d2.Subtract(d1).Days ;i++)
{
//如果这一天不等于星期六并且也不等于星期天。。。
if(TempD.DayOfWeek != DayOfWeek.Saturday & TempD.DayOfWeek != DayOfWeek.Sunday )
{
L.Add(TempD.Year + "." + TempD.Month + "." + TempD.Day + " " + TempD.DayOfWeek);
}
TempD = TempD.AddDays(1);
}
for (int i = 0; i < L.Count ; i++)
{
Console.WriteLine(L[i]);
}
public static IEnumerable<DateTime> GetDatesBetween(DateTime d1, DateTime d2)
{
while (d1 <= d2)
{
yield return d1;
d1 = d1.AddDays(1);
}
}
//...........
var result = GetDatesBetween(new DateTime(2014, 2, 1), new DateTime(2014, 3, 28))
.Where(a => a.DayOfWeek != DayOfWeek.Saturday && a.DayOfWeek != DayOfWeek.Sunday).ToList();
result.ForEach(a =>
{
Console.WriteLine(a);
});
var L= Enumerable.Range(0, d2.Subtract(d1).Days+1)
.Select((x,i)=>new {date=d1.AddDays(i).ToString("yyyy.MM.dd"), d1.AddDays(i).DayOfWeek})
.Where(t=>t.DayOfWeek!=DayOfWeek.Saturday &&am