1.获取当前时间时间戳
const currentTime=(new Date()).getTime()
2.获取当前时间的前N天
const beforeTime=currentTime-N*24*60*60*1000 //前N天的时间戳
const before=new Date(beforeTime) //如下格式:Fri Oct 07 2022 18:35:28 GMT+0800 (中国标准时间)
由当前获取的时间从而获取当前年月日:
const year =before.getFullYear() //2022
const month=before.getMonth+1 //10
const day=before.getDate //07
3.获取当前时间的后N天
const afterTime=currentTime+N*24*60*60*1000 //前N天的时间戳
const after=new Date(afterTime) //如下格式:Fri Oct 07 2022 18:35:28 GMT+0800 (中国标准时间)
由当前获取的时间从而获取当前年月日:
const year =after.getFullYear() //2022
const month=after.getMonth+1 //10
const day=after.getDate //07