- 獲取當(dāng)前日期
new Date() // Wed May 25 2022 10:30:50 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)
- 獲取30天前的日期
new Date(new Date() - 1000 * 60 * 60 * 24 * 30); // Mon Apr 25 2022 10:32:52 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)
- 獲取30年前的日期
new Date(new Date() - (1000 * 60 * 60 * 24 * 30 * 12 * 30)); // Thu Oct 29 1992 10:33:49 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)
當(dāng)然也可以用dayjs或者moment.js插件來(lái)獲取時(shí)間