Calculates the date for the specified number of days before

1. Direct copy to debug

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
}

Guess you like

Origin blog.csdn.net/weixin_44949068/article/details/130007189