funDate(data,timeInterval) {
var currDate = new Date(data)
var beforeOneWeekDate = new Date(currDate)
beforeOneWeekDate.setDate(currDate.getDate() - timeInterval)
let year2 = beforeOneWeekDate.getFullYear()
let month2 = beforeOneWeekDate.getMonth() + 1
let day2 = beforeOneWeekDate.getDate()
if (parseInt(month2) < 10) {
month2 = '0' + month2
}
if (parseInt(day2) < 10) {
day2 = '0' + day2
}
var hour = currDate.getHours(); // 时
if (hour >= 0 && hour <= 9) {
hour = "0" + hour;
}
var minutes = currDate.getMinutes(); // 分
if (minutes >= 0 && minutes <= 9) {
minutes = "0" + minutes;
}
var seconds = currDate.getSeconds() //秒
if (seconds >= 0 && seconds <= 9) {
seconds = "0" + seconds;
}
var formatBeforeOneWeekDate = year2 + '-' + month2 + '-' + day2 + ' ' + hour + ':' + minutes + ':' + seconds
return formatBeforeOneWeekDate
}
使用:funDate(data,X)
data:时间
X:天数 负数未之后 正数为之前