任意一个月,我想得到这个月的最后一天这个数值,c#有这个函数吗?

解决方案 »

  1.   

    某个月最后一天不就是这一个月的天数?
    System.DataTime.DaysInMonth() 方法
      

  2.   

    using System;
    using System.Collections;public class MyClass
    {
    public static void Main()
    {
    // 如 2005-11 月
    String yearMonth = "2005-11";
    DateTime dt = DateTime.Parse(yearMonth + "-01");
    dt = dt.AddMonths(1);
    DateTime lastDay = dt.AddDays(-1);
    Console.WriteLine("最后一天是:{0}",lastDay.Day);
    Console.ReadLine();
    }

    }
      

  3.   

    DateTime dt = System.DateTime.Now; //获得当前日期 dt = dt.AddDays(1 - dt.Day);        //得到当月的第一天日期
    dt = (dt.AddMonths(1)).AddDays(-1);      //得到当月的最后一天日期
      

  4.   

    /// <summary>
    /// 获得某月最后一天的数值
    ///  Returns:最后一天的数值
    /// </summary> 
    /// <param name = "p_dTime"> 需要提取的时间 </param>
    /// <returns> 最后一天的数值 </returns>
    public int GetDay(DateTime p_dTime)
    {
        int intResult = 0;
        switch (p_dTime.Month.ToString())
        {
            case "1":
            case "3":
            case "5":
            case "7":
            case "8":
            case "10":
            case "12":
                intResult = 31;
                break;
            case "4":
            case "6":
            case "9":
            case "11":
                intResult = 30;
                break;
            case "2":
                if ((Convert.ToInt16(p_dTime.Year) % 4 == 0) &&
                    (Convert.ToInt16(p_dTime.Year) % 100 != 0) ||
                    (Convert.ToInt16(p_dTime.Year) % 400 == 0))
                    intResult = 29;
                else
                    intResult = 28;
                break;
        }
        return intResult;
    }
      

  5.   

    int mydays =System.DateTime.DaysInMonth(2005,11)
      

  6.   

    using System;
    using System.Collections;public class MyClass
    {
    public static void Main()
    {
    // 如 2005-11 月
    String yearMonth = "2005-11";
    DateTime dt = DateTime.Parse(yearMonth + "-01");
    dt = dt.AddMonths(1);
    DateTime lastDay = dt.AddDays(-1);
    Console.WriteLine("最后一天是:{0}",lastDay.Day);
    Console.ReadLine();
    }

    }
      

  7.   

    System.DateTime today = System.DateTime.Now;
    System.DateTime NextMonth= today.AddMonths(1);
    System.DateTime NextMonthFirstDay=System.DateTime(NextMonth.Yesr,NextMonth.Month,1)
    System.DateTime lastday = NextMonthFirstDay.AddDays(-1);
      

  8.   

    DataTime.DaysInMonth() 方法已经有的方法为什么要自己写?
      

  9.   

    System.DateTime.DaysInMonth(2005,8)//获取2005年8月的总天数,即最后一天
      

  10.   

    SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
      

  11.   

    本月最后一天
    SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
      

  12.   

    DECLARE @dt datetime
    SET @dt=GETDATE()
    SELECT DATEADD(Day,-1,CONVERT(char(8),DATEADD(Month,1,@dt),120)+'1')
      

  13.   

    ==>最后一天这个数值
    难道不是这个月的总天数么?.NET里面有内置的方法不用为什么要自己写???
      

  14.   

    DataTime.DaysInMonth() 
    这应该可以吧?!
    *_*
      

  15.   

    Date.DaysInMonth(Year(Now), Month(Now))