> 文章列表 > 计算指定前几天的日期

计算指定前几天的日期

计算指定前几天的日期

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() + 1const D = myDate.getDate()let dateGet = `${Y}-${M}-${D}`return dateGet
}