获取某天前几天的方法

function getBeforeDate() {
	let data = [];
	let date = new Date();
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let today = date.getDate();
	let lastMonthdays = new Date(year, month - 1, 0).getDate();
	//以当前日期前一天为日期,获取前7天日期
	for (let i = 0; i < 7; i++) {
		if (today - 1 < 1) {
			today = lastMonthdays;
			if (month - 1 < 1) {
				month = 12;
			} else {
				month = month - 1;
			}
			let d = month + '.' + today;
			data.unshift(d);
		} else {
			today = today - 1;
			let d = month + '.' + today;
			data.unshift(d);
		}
	}
	return data;
}

你可能感兴趣的:(学习笔记)