昨天用公式实现某一日期是第几周的计算,今天用c#实现。
private int WeekOfYear(DateTime dt)
{
string firstdayofyear = dt.Year.ToString() + "-01-01";
DateTime firstday = Convert.ToDateTime(firstdayofyear);
int weekday=(int)firstday.DayOfWeek;
int weeknum = (dt.DayOfYear + weekday - 2) / 7 + 1;
return weeknum;
}
{
string firstdayofyear = dt.Year.ToString() + "-01-01";
DateTime firstday = Convert.ToDateTime(firstdayofyear);
int weekday=(int)firstday.DayOfWeek;
int weeknum = (dt.DayOfYear + weekday - 2) / 7 + 1;
return weeknum;
}