获取当前日期,29天之后的日期,兼容2月,等特殊日期
可以试下这个:
let date = new Date();
date.setDate(date.getDate() + 29);
console.log(date.toDateString());
var date1 = new Date();
var date2 = new Date(date1);
date2.setDate(date1.getDate() + 29);
console.log(date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate());
一般来说都是引入 dayjs 或者 momentjs
来处理,当然也可以和 @Bestime 一样,直接操作 Date
对象。
以下是 dayjs
的操作方式:
import dayjs from 'dayjs'
// 当前日期
const currentDate = dayjs()
// 29天之后的日期
const after29day = currentDate.add(29,'day')
// 按照 YYYY-MM-DD 的格式输出
console.log(after29day.format('YYYY-MM-DD'))
// log 2023-03-03
16 回答2.8k 阅读✓ 已解决
6 回答4.1k 阅读✓ 已解决
9 回答3.4k 阅读✓ 已解决
14 回答5.3k 阅读
7 回答1.7k 阅读
14 回答2k 阅读
3 回答970 阅读✓ 已解决