首页 > 代码库 > 根据日期计算出周一和周日

根据日期计算出周一和周日

http://stackoverflow.com/questions/2821035/c-sharp-get-start-date-and-last-date-based-on-current-date

DateTime baseDate = DateTime.Today;var today = baseDate;var yesterday = baseDate.AddDays(-1);var thisWeekStart = baseDate.AddDays(-(int)baseDate.DayOfWeek);var thisWeekEnd = thisWeekStart.AddDays(7).AddSeconds(-1);var lastWeekStart = thisWeekStart.AddDays(-7);var lastWeekEnd = thisWeekStart.AddSeconds(-1);var thisMonthStart = baseDate.AddDays(1 - baseDate.Day);var thisMonthEnd = thisMonthStart.AddMonths(1).AddSeconds(-1);var lastMonthStart = thisMonthStart.AddMonths(-1);var lastMonthEnd = thisMonthStart.AddSeconds(-1);

 

根据日期计算出周一和周日