/**根据现有日期往前或者往后多少天,推算出日期**/
export const calculateTime = (date, d) => {
//把时分秒设置为0,不需要就直接注释掉就好了
let now = new Date(date)
now.setDate(now.getDate() + d);
const year = now.getFullYear();
const month = now.getMonth() + 1;
const day = now.getDate();
return `${year}-${month}-${day}`;
}
// calculateTime('2021-12-10',-7) 往前推7天
// calculateTime('2021-12-10', 7) 往后推7天
根据某个日期计算出往前或者往后多少天的日期
最新推荐文章于 2022-07-21 17:32:18 发布