[JS] According to the date and the given number of days, calculate the date and time of the first few days or the next few days of the date


/**
 * 近几天,返回传入值的天数
 * @param { Date } date 日期时间:new Date() 或者 字符串日期 2002-03-04
 * @param { number } day 传入几,就是几天,负数,今天之前的天数,正数今天以后的天数
 * @returns 第几天的日期 格式:2022-02-04
 */
const inRecentDays = (date = new Date(), day = -7) => formatDate(new Date(new Date(date).getTime() + (86400000 * day)));

About the formatDate function, please click this text to view

Guess you like

Origin blog.csdn.net/weixin_44244230/article/details/132087271