比如说 我给你一个年份月份  如 2010-8  我想知道2010年8月一共有多少天 。请问大侠们 如何做

解决方案 »

  1.   

    dt1 2010-8-1
    dt1+1月 dt2 2010-9-1timespan dt2-dt1
      

  2.   

    System.DateTime.DaysInMonth(指定年,指定月);   
        
      int   idate=System.DateTime.DaysInMonth(2006,6);   
        
      返回值     idate     30
      

  3.   

     int days = DateTime.DaysInMonth(2010, 8);
      

  4.   

    DateTime.DaysInMonth(year, month);
      

  5.   

    最简单的就是int days = DateTime.DaysInMonth(2001, 10);也可以通用加一个月,相减来计算
     DateTime   dt1   =   DateTime.Now;   
      dt1   =   new   DateTime(dt1.Year,   dt1.Month,   1);   
      DateTime   dt2   =   dt1.AddMonths(1);   
      dt2   =   new   DateTime(dt2.Year,   dt2.Month,   1);   
      int   days   =   (dt2-dt1).Days;   
      

  6.   

    不废话int days = DateTime.DaysInMonth(2001, 10);
      

  7.   

    Int32 days = DateTime.DaysInMonth(2010, 8);
      

  8.   

     DateTime.DaysInMonth(2010, 8);