function test() {
//上个月第一天
console.log(getfirstMonth(-1))
//上个月最后一天
console.log(getlastMonth(-1))
//本月第一天
console.log(getfirstMonth(0))
//本月最后一天
console.log(getlastMonth(0))
//下个月第一天
console.log(getfirstMonth(1))
//下个月最后一天
console.log(getlastMonth(1))
}
//月开始时间
function getfirstMonth(n){
return Timetools(1,n);
}
//月结束时间
function getlastMonth(n){
return Timetools(0,n);
}
function Timetools(num,n) {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1+n;
var date=new Date(year, month,num).getDate();
var s = year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date);
return s;
}
我们一路奋战,不是为了改变世界,而是为了不让世界改变我们。 ——《熔炉》