想直接得到某一个日期所在月的第一天和最后一天,在网上查了半天也没找到一个好的办法,最后自己想了一个好办法,和大家分享一下:
得到第一天:
DateTime.Now.AddDays(1 - DateTime.Now.Day);
得到最后一天:
DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1);谁有更好的办法,贴出来分享一下.

解决方案 »

  1.   

    DateTime.DaysInMonth(2009,5)得到的是一个INT的数值,在这里想要的是一个日期类型的值
      

  2.   

    DateTime.MaxValue.AddDays(1 - DateTime.MaxValue.Day).AddMonths(1).AddDays(-1); 
      

  3.   

    当月的天数出来了,还得不到DateTime类型吗……
    int year = DateTime.Now.Year;
    int month = DateTime.Now.Month;
    int day = DateTime.DaysInMonth(year,month);
    DateTime dt = new DateTime(year,month,day);
      

  4.   

                DateTime dt1 = new DateTime(2009, 5, 1);
                DateTime dt2 = new DateTime(2009, 5, DateTime.DaysInMonth(2009, 5));