//本周是本年第幾周
private int DatePart(System.DateTime dt)
{
int weeknow = Convert.ToInt32(dt.DayOfWeek);//今天星期幾
int daydiff = (-1) * (weeknow+1);//今日與上周末的天數差
int days = System.DateTime.Now.AddDays(daydiff).DayOfYear;//上周末是本年第幾天
int weeks = days/7;
if(days%7 != 0)
{
weeks++;
}
//此時,weeks為上周是本年的第幾周
return (weeks+1);
}
//本周起止日期
private string WeekRange(System.DateTime dt)
{
int weeknow = Convert.ToInt32(dt.DayOfWeek);
int daydiff = (-1) * weeknow;
int dayadd = 6-weeknow;
string dateBegin = System.DateTime.Now.AddDays(daydiff).Date.ToString("MM月dd日");
string dateEnd = System.DateTime.Now.AddDays(dayadd).Date.ToString("MM月dd日");
return dateBegin + " - " +dateEnd;
}