日期:2014-05-17 浏览次数:20451 次
public int TotalWorkday(DateTime AStart, DateTime AEnd)
{
TimeSpan vTimeSpan = new TimeSpan(AEnd.Ticks - AStart.Ticks);
// 跨度多少个星期,每个星期5个工作日
int Result = ((int)vTimeSpan.TotalDays / 7) * 5;
// 计算余下的日期中的工作日
for (int i = 0; i <= vTimeSpan.TotalDays % 7; i++)
switch (AStart.AddDays(i).DayOfWeek)
{
case DayOfWeek.Saturday:
case DayOfWeek.Sunday:
break;
default:
Result++;
break;
}
return Result;
} /* TotalWorkday */
private void button1_Click(object sender, EventArgs e)
{
Text = TotalWorkday(new DateTime(2007, 4, 6),
new DateTime(2007, 4, 11)).ToString();
}