.Net WeekOfYear 获取日期所属于一年中的第几周
/// <summary>
/// 获取某天所在的周,是一年当中的第几周
/// </summary>
/// <param name="dt">日期</param>
/// <returns></returns>
public static int WeekOfYear(DateTime dt)
{
//CultureInfo ci = CultureInfo.GetCultureInfo("zh-CN");//时区
//①强制设置周一是每周的第一天
//return ci.Calendar.GetWeekOfYear(dt, ci.DateTimeFormat.CalendarWeekRule, DayOfWeek.Monday);//自定义周一或周日为一周的第一天,用这个
//②根据时区性信息对象设置每周的第一天
//return ci.Calendar.GetWeekOfYear(dt, ci.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.FirstDayOfWeek);//根据时区自动判断周一或周日为一周的第一天,默认用这个
//同方法①
return new GregorianCalendar().GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
}
调用:
obj.StartDate = DateTime.Now;
obj.WeekOfYear = PMP_Daily_BLL.WeekOfYear(obj.StartDate);//周是年度第几个周
实际运用: https://blog.csdn.net/djk8888/article/details/143058344