js 日期加减操作(日、月、年)
- 先定义当前时间
const myDate = new Date()
2.日期加减操作
myDate.setYear(myDate.getFullYear() + 1) //增加一年
myDate.setMonth(myDate.getMonth() + 1) //增加一个月
myDate.setDate(myDate.getDate() + 1) //增加一天
myDate.getTime() + (86400 * 1 * 1000) //增加一天(使用时间戳)
3.输出格式为年-月-日
getData(val) { // 时间戳转换为年月日
n = new Date(val)
return n.toLocaleDateString().replace(/\//g, '-')
}