配色: 字号:
已知当前日期计算本周、月、季度、年的日期.doc
2013-03-18 | 阅:  转:  |  分享 
  
DateTimedt=DateTime.Now;//当前时间



DateTimestartWeek=dt.AddDays(1-Convert.ToInt32(dt.DayOfWeek.ToString("d")));//本周周一

DateTimeendWeek=startWeek.AddDays(6);//本周周日



DateTimestartMonth=dt.AddDays(1-dt.Day);//本月月初

DateTimeendMonth=startMonth.AddMonths(1).AddDays(-1);//本月月末

//DateTimeendMonth=startMonth.AddDays((dt.AddMonths(1)-dt).Days-1);//本月月末



DateTimestartQuarter=dt.AddMonths(0-(dt.Month-1)%3).AddDays(1-dt.Day);//本季度初

DateTimeendQuarter=startQuarter.AddMonths(3).AddDays(-1);//本季度末



DateTimestartYear=newDateTime(dt.Year,1,1);//本年年初

DateTimeendYear=newDateTime(dt.Year,12,31);//本年年末

献花(0)
+1
(本文系红人1317首藏)