比如我输入的是2008-06
怎么样才能得到08年6月份的第一天和最后一下呢?
(2008-06)可以随意变换年份和月份

解决方案 »

  1.   


    int year = 2008;
    int month = 6;DateTime FirstDay = new DateTime(year, month, 1);
    DateTime LastDay = FirstDay.AddMonth(1).AddDays(-1);
      

  2.   

    第一天都是1,
    若月份为1、3、5、7、8、10、12都31
                    4、6、9、11都30
    主要就是2月份,DateTiem.IsLeapYear(年份)==true 表示闰年,则为29,反之为28。
      

  3.   

    应该是DateTime.IsLeapYear(年份)==true 表示闰年,则为29,反之为28。
      

  4.   

    不是整百年数的能整除4的是闰年 
    是整百年数的能整除400的是闰年不想用DateTime.IsLeapYear(年份),就自己写if(年份%100!=0)
    {
       if(年份%4==0)
        {
           return 29;
        }
       else
        {
           return 28;
        }
    }
    else
    {
       if(年份%400==0)
         {
           return 29;
         }
       else
         {
           return 28;
         }
    }
      

  5.   


    int year = 2008;
    int month = 6;DateTime FirstDay = new DateTime(year, month, 1);
    DateTime LastDay = new DateTime(year,month,DateTime.DaysInMonth(year,month));
      

  6.   

    DaysInMonth方法即可.
    返回值是
    指定 year 中 month 的天数。 例如,如果 month 等于 2(表示二月),则返回值为 28 或 29,具体取决于 year 是否为闰年
      

  7.   


    int year = 2008;
    int month = 6;DateTime first = new DateTime(year, month, 1);
    DateTime last = new DateTime(year,month,DateTime.DaysInMonth(year,month));
      

  8.   

    每月开始是一号
    最後一天System.DateTime.DaysInMonth(System.DateTime.Now.Year,System.DateTime.Now.Month)
      

  9.   

    去掉日部分,改成01就是第一天
    ADD一个月,就到下个月的第一天了,然后在ADD负一天,就到上个月最后一天了