获取特定月的最后一天

2018-05-28  本文已影响0人  有一个程序媛

//获得某月的最后一天

function getLastDay(year,month) {

var new_year = year;    //取当前的年份

    var new_month = month++;//取下一个月的第一天,方便计算(最后一天不固定)

    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();//获取当月最后一天日期

}

getLastDay(‘2018’,‘05’) ------31

getLastDay(‘2018’,‘04’) ------30

上一篇 下一篇

猜你喜欢

热点阅读