参数说明:day:要判断的日期,WeekStart:1周一为一周的开始,2周日为一周的开始
public static int WeekOfMonth(DateTime day, int WeekStart)
{
//WeekStart
//1表示 周一至周日 为一周
//2表示 周日至周六 为一周
DateTime FirstofMonth;
FirstofMonth = Convert.ToDateTime(day.Date.Year + "-" + day.Date.Month + "-" + 1);
int i = (int)FirstofMonth.Date.DayOfWeek;
if (i == 0)
{
i = 7;
}
if (WeekStart == 1)
{
return (day.Date.Day + i - 2) / 7 + 1;
}
if (WeekStart == 2)
{
return (day.Date.Day + i - 1) / 7;
}
return 0;
//错误返回值0
}
///
/// 根据日期查询当天是当年的多少周
///
///
///
public static int GetDayOfWeek(DateTime date)
{
return date.DayOfYear / 7 + 1;
}
代码提示:public int GetWeekNum(DateTime dt){ return dt.DayOfYear / 7 + 1;}
唉,审核没通过