计算指定前几天的日期

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
}

猜你喜欢

转载自blog.csdn.net/weixin_44949068/article/details/130007189