JS 获取指定日期的前几天,后几天

getDay=function(e,days){
var year = e.split('-')[0]
var month = e.split('-')[1] - 1  //由于月份需要-1,如2月就是1
var day = e.split('-')[2]
var date = new Date(year, month, day)
//这里的days就是你要加的天数,减也可以
date.setDate(date.getDate() + days)
console.log(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate())
}

输入格式getDay("2019-8-16",1)

猜你喜欢

转载自blog.csdn.net/weixin_42776027/article/details/99941880