获取一个月份中最早的一天和最后的一天。在C#的DateTime类中,已经提供了现成的函数,下面分别用两个简单的函数表示:

private DateTime GetFirstDayOfMonth(int Year,int Month)
        {
          //你见过不是从1号开始的月份么?没有
            //那么,直接返回给调用者吧!
            //良好的一个编程习惯就是你的代码让人家看了简单易懂
          
          return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-1");
        }商账追收

private DateTime GetLastDayOfMonth(int Year, int Month)
        {
            //这里的关键就是 DateTime.DaysInMonth 获得一个月中的天数         
              int Days = DateTime.DaysInMonth(Year, Month);
            return Convert.ToDateTime(Year.ToString() + "-" + Month.ToString() + "-" + Days.ToString());
        }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2021-11-29
  • 2022-12-23
  • 2023-03-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
相关资源
相似解决方案