C#获取指定日期所在周/月/年的起始时间

以下内容转自http://www.cnblogs.com/musickh/archive/2009/07/16/1524912.html,在此多谢博主!

 

DateTime.Now=2009-7-16 5:20:56

//今天

DateTime.Now.Date.ToString(); "2009-7-16 0:00:00"

//周起始日期

DateTime.Now.Date.AddDays(-(int)(DateTime.Now.DayOfWeek)+1).ToString(); {2009-7-13 0:00:00} DateTime.Now.Date.AddDays(7-(int)(DateTime.Now.DayOfWeek)).ToString(); {2009-7-19 0:00:00}

//月起始日期 new DateTime(DateTime.Now.Year,DateTime.Now.Month,1).ToString(); {2009-7-1 0:00:00}

new   DateTime(DateTime.Now.Date.Year,DateTime.Now.Date.Month,DateTime.DaysInMonth(DateTime.Now.Date.Year,DateTime.Now.Date.Month)).ToString(); "2009-7-31 0:00:00"

//年起始日期 new   DateTime(DateTime.Now.Date.Year,1,1).ToString(); {2009-1-1 0:00:00} new   DateTime(DateTime.Now.Date.Year,12,DateTime.DaysInMonth(DateTime.Now.Date.Year,DateTime.Now.Date.Month)).ToString(); {2009-12-31 0:00:00}

posted @ 2013-04-23 13:23  louiskoo  阅读(2767)  评论(0编辑  收藏  举报