js得到每个月的最后一天或者区分每个月有多少天

解决方案 »

  1.   


    取月的最后一天
    function getLastDay(year,month)
    {
     //取年
     var new_year = year;
     //取到下一个月的第一天,注意这里传入的month是从1~12 
     var new_month = month++;
     //如果当前是12月,则转至下一年
     if(month>12)
     {
      new_month -=12;
      new_year++;
     }
     var new_date = new Date(new_year,new_month,1);
     return (new Date(new_date.getTime()-1000*60*60*24)).getDate();
    }
    请参考第172个知识点