/// <summary>
/// 获取日期是第几周
/// </summary>
/// <param name="date">日期</param>
/// <returns>第几周</returns>
public static int GetWeekOfYear(DateTime date)
{
//确定此时间在一年中的位置
int dayOfYear = date.DayOfYear;
//当年第一天
DateTime tempDate = new DateTime(date.Year, 1, 1);
//确定当年第一天
int tempDayOfWeek = (int)tempDate.DayOfWeek;
tempDayOfWeek = tempDayOfWeek == 0 ? 7 : tempDayOfWeek;
//确定星期几
int index = (int)date.DayOfWeek;
index = index == 0 ? 7 : index;
//当前周的范围
DateTime retStartDay = date.AddDays(-(index - 1));
DateTime retEndDay = date.AddDays(7 - index);
//确定当前是第几周
int weekOfYear = (int)Math.Ceiling(((double)dayOfYear + tempDayOfWeek - 1) / 7);
if (retStartDay.Year < retEndDay.Year)
{
weekOfYear = 1;
}
return weekOfYear;
}