/**根据现有日期往前或者往后多少天,推算出日期**/
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天 版权声明:本文为weixin_47756693原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。