计算指定前几天的日期

1、直接copy去调试

export function getTheSpecifiedDate(date, theOtherDay) {
	let myDate = new Date(date); //获取今天日期
	myDate.setDate(myDate.getDate() - theOtherDay); //获取指定前几天的日期
	const Y = myDate.getFullYear()
	const M = myDate.getMonth() + 1 < 10 ? '0' + (myDate.getMonth() + 1) : myDate.getMonth() + 1
	const D = myDate.getDate()
	let dateGet = `${Y}-${M}-${D}`
	return dateGet
}

你可能感兴趣的:(JavaScript,javascript,开发语言,ecmascript)