-
public void getDays()
{
DateTime dt1 = new DateTime(2010, 01, 01);//初始化一个日期
DateTime dt2 = DateTime.Now;//获取今天日期
TimeSpan ts1 = dt1.Subtract(dt2);//TimeSpan得到dt1和dt2的时间间隔
int countday = ts1.Days;//获取两个日期间的总天数
int weekday = 0;//工作日
//循环用来扣除总天数中的双休日
for (int i = 0; i < countday; i++)
{
DateTime tempdt = dt1.Date.AddDays(i);
if (tempdt.DayOfWeek != System.DayOfWeek.Saturday && tempdt.DayOfWeek != System.DayOfWeek.Sunday)
{
weekday++;
}
}
Response.Write("总天数:" + countday.ToString());
Response.Write("工作日:" + weekday.ToString());