在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、得到本周的第一天和最后一天 1 /// <summary> 2 /// 得到本周第一天(以星期一为第一天) 3 /// </summary> 4 /// <param name="datetime"></param> 5 /// <returns></returns> 6 public DateTime GetWeekFirstDayMon(DateTime datetime) 7 { 8 //星期一为第一天 9 int weeknow = Convert.ToInt32(datetime.DayOfWeek); 10 11 //因为是以星期一为第一天,所以要判断weeknow等于0时,要向前推6天。 12 weeknow = (weeknow == 0 ? (7 - 1) : (weeknow - 1)); 13 int daydiff = (-1) * weeknow; 14 15 //本周第一天 16 string FirstDay = datetime.AddDays(daydiff).ToString("yyyy-MM-dd"); 17 return Convert.ToDateTime(FirstDay); 18 } 19 /// <summary> 20 /// 得到本周最后一天(以星期天为最后一天) 21 /// </summary> 22 /// <param name="datetime"></param> 23 /// <returns></returns> 24 public DateTime GetWeekLastDaySun(DateTime datetime) 25 { 26 //星期天为最后一天 27 int weeknow = Convert.ToInt32(datetime.DayOfWeek); 28 weeknow = (weeknow == 0 ? 7 : weeknow); 29 int daydiff = (7 - weeknow); 30 31 //本周最后一天 32 string LastDay = datetime.AddDays(daydiff).ToString("yyyy-MM-dd"); 33 return Convert.ToDateTime(LastDay); 34 }
|
请发表评论