/// <summary>
/// 获取指定年月的当月工作日,不支持国家法定节假日的判断和计算,只计算周六和周日为非工作日
/// </summary>
/// <param name="year">年份</param>
/// <param name="month">月份</param>
/// <returns>返回指定月份的当月工作日天数</returns>
public int GetWorkingDays(int year,int month)
{
//获取该月的第一天
DateTime dateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-01"));
//获取该月总计天数
int days = DateTime.DaysInMonth(year,month);
//休息天数
int weekDays = 0;
for (int i = 0; i < days; i++)
{
//每逢周六/周日 休息天数增加一天
switch (dateTime.DayOfWeek)
{
case DayOfWeek.Sunday:
weekDays++;
break;
case DayOfWeek.Saturday:
weekDays ++;
break;
default:
break;
}
dateTime.AddDays(1);
}
//工作日等于当月总天数减去非工作日
int workDays = days - weekDays;
return workDays;
}