日期:2014-05-17 浏览次数:20796 次
/**//// <summary>
/// 得到一年中的某周的起始日和截止日
/// 年 nYear
/// 周数 nNumWeek
/// 周始 out dtWeekStart
/// 周终 out dtWeekeEnd
/// </summary>
/// <param name="nYear"></param>
/// <param name="nNumWeek"></param>
/// <param name="dtWeekStart"></param>
/// <param name="dtWeekeEnd"></param>
public static void GetWeek(int nYear, int nNumWeek, out DateTime dtWeekStart, out DateTime dtWeekeEnd)
{
DateTime dt = new DateTime(nYear, 1, 1);
dt = dt + new TimeSpan((nNumWeek - 1) * 7, 0, 0, 0);
dtWeekStart = dt.AddDays(-(int)dt.DayOfWeek + (int)DayOfWeek.Monday);
dtWeekeEnd = dt.AddDays((int)DayOfWeek.Saturday - (int)dt.DayOfWeek + 1);
}
/**//// <summary>
/// 求当前日期是一年的中第几周
/// </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);