怎么知道该月有多少天呢?

解决方案 »

  1.   

    int m=System.DateTime.DaysInMonth(System.DateTime.Now.Year,System.DateTime.Now.Month);
      

  2.   

    例如 
    DateTime d1 =new DateTime(2005-9-1);开始 日期 
    DateTime d2 =new DateTime(2005-10-1);结束 日期 
    TimeSpan d3 = d2.Subtract(d1); 相差 天数
      

  3.   

    #region 如何得到某月总共有多少天
    //传入某月的某一个日期即可
    public static int getLastDayOfMonth(System.DateTime date)
    {
    return System.DateTime.DaysInMonth(date.Year,date.Month);
    }
    #endregion
      

  4.   

    小山正解:
    int n = System.DateTime.DaysInMonth(dt.Year, dt.Month);还可以换一种思路:
    int n = dt.AddDays(1-dt.Day).AddMonths(1).AddDays(-1).Day;如果想获得某个日期dt的该月的最后一天的话:
    System.DateTime LastDayOfMonth = dt.AddDays(1-dt.Day).AddMonths(1).AddDays(-1);