DateTime nowTime = DateTime.Now; #region 获取本周第一天 //星期一为第一天 int weeknow = Convert.ToInt32(nowTime.DayOfWeek); //因为是以星期一为第一天,所以要判断weeknow等于0时,要向前推6天。 weeknow = (weeknow == 0 ? (7 - 1) : (weeknow - 1)); int daydiff = (-1) * weeknow; //本周第一天 DateTime FirstDay = nowTime.AddDays(daydiff);
#endregion #region 获取本周最后一天 //星期天为最后一天 int lastWeekDay = Convert.ToInt32(nowTime.DayOfWeek); lastWeekDay = lastWeekDay == 0 ? (7 - lastWeekDay) : lastWeekDay; int lastWeekDiff = (7 - lastWeekDay); //本周最后一天 DateTime LastDay = nowTime.AddDays(lastWeekDiff);
#endregion