110,536
社区成员
发帖
与我相关
我的任务
分享
/// 求当前日期是一年的中第几周
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static int WeekOfYear(DateTime curDay)
{ int firstdayofweek = Convert.ToInt32(Convert.ToDateTime(curDay.Year.ToString() + "- " + "1-1 ").DayOfWeek);
int days = curDay.DayOfYear;
int daysOutOneWeek = days - (7 - firstdayofweek);
if (daysOutOneWeek <= 0)
{
return 1;
}
else
{
int weeks = daysOutOneWeek / 7;
if (daysOutOneWeek % 7 != 0)
weeks++;
return weeks + 1; }
int daysOutOneWeek = days - (7 - firstdayofweek + 1);
后面+1.