let data1 = [];
function getDay(day) {
var today = new Date();
var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
today.setTime(targetday_milliseconds);
var tYear = today.getFullYear();
var tMonth = today.getMonth();
var tDate = today.getDate();
tMonth = doHandleMonth(tMonth + 1);
tDate = doHandleMonth(tDate);
// return tYear+"-"+tMonth+"-"+tDate; //年月日
return tMonth + "-" + tDate; //月日
}
function doHandleMonth(month) {
var m = month;
if (month.toString().length == 1) {
m = "0" + month;
}
return m;
}
function dsdd(e) { //拼接
data1.splice(0);//请控之前的数据
for (let i = 0; i < e; i++) {
data1.push(getDay(-i));//-i 代表之前 i代表将来
}
}
//dsdd(7); //前7
//dsdd(30) //前30
console.log( data1 )
前端一些小技巧
欢迎讨论