如何计算当前日期是当年的第几周?

Method 1
CultureInfo ci = CultureInfo.CurrentCulture;
Calendar cal = ci.Calendar;
CalendarWeekRule cwr = ci.DateTimeFormat.CalendarWeekRule;
DayOfWeek dow = ci.DateTimeFormat.FirstDayOfWeek;
int i = cal.GetWeekOfYear(DateTime.Now,cwr,dow);

Method 2
int i;
if(DateTime.Now.DayOfYear%7==0)
    i=DateTime.Now.DayOfYear/7;
else
    i=DateTime.Now.DayOfYear/7 + 1;

你可能感兴趣的:(如何计算当前日期是当年的第几周?)