DateTime startWeek = dt.AddDays(1-((dayOfWeek == 0)?7:dayOfWeek)); //本周周一DateTime endWeek = startWeek.AddDays(6); //本周周日 DateTime startMonth = dt.AddDays(1 - dt.Day); //本月月初DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); //本月月末//DateTime endMonth = startMonth.AddDays((dt.AddMonths(1) - dt).Days - 1); //本月月末 DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day); //本季度初DateTime endQuarter = startQuarter.AddMonths(3).AddDays(-1); //本季度末 DateTime startYear = new DateTime(dt.Year, 1, 1); //本年年初DateTime endYear = new DateTime(dt.Year, 12, 31); //本年年末
int dayOfWeek = Convert.ToInt32(dt.DayOfWeek.ToString("d")); 至于昨天、明天、上周、上月、上季度、上年度等等,只要AddDays()、AddMonths()、AddYears()这几种方法组合一下就可以了。转载于:https://www.cnblogs.com/n666/archive/2010/10/09/2190886.html
相关资源:数据结构—成绩单生成器