获取当月的月初和月末
刚碰见个这样的需求,忽然之间发现不会写,度娘以后记录下来分享一下
function getLastDay(){
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
if(month>12){
month -=12;
year++;
}
var new_date = new Date(year,month,1);
var pre_month = "";
if(month < 10){
pre_month = "0";
}
var first = "" + year + "-" + pre_month + month + "-01" + " 00:00:00";
var end = "" + year + "-" + pre_month + month + "-" + (new Date(new_date.getTime()-1000*60*60*24)).getDate() + " 23:59:59";
console.log(first)
console.log(end)
console.log(new Date(new_date.getTime()))
console.log(new Date(new_date.getTime()-1000*60*60*24) + "23:59:59")
}