自定义方法,用于获取本月或指定月份的最后一天,如果不传参数,就是当前月:
function getMonthFinalDay(year,month){var day=‘‘;if(year==null || year==undefined || year==‘‘){year = new Date().getFullYear();}if(month==null || ?month==undefined || month==‘‘){month = new Date().getMonth()+1;}day = new Date(new Date(year,month).setDate(0)).getDate();return year+"-"+month+"-"+day;}
调用方式:
getMonthFinalDay();//2017-10-31getMonthFinalDay(2016);//2016-10-31getMonthFinalDay(2017,9);//2017-9-30
js获取本月或指定月份的最后一天
原文地址:http://www.cnblogs.com/YuanFan123/p/7682212.html