js获取当前日期与7天后的日期

调用

console.log(this.getSectionData(7))

结果
js获取当前日期与7天后的日期_第1张图片
函数

getSectionData(section) {
				const now = new Date()
				const nowYear = now.getFullYear()
				const nowMonth = now.getMonth() + 1 < 10 ? ('0' + (now.getMonth() + 1)) : (now.getMonth() + 1)
				const nowDay = now.getDate() < 10 ? ('0' + now.getDate()) : now.getDate()
				let newDate = new Date();
				newDate.setDate(newDate.getDate() + section);
				const newYear = newDate.getFullYear()
				const newMonth = newDate.getMonth() + 1 < 10 ? ('0' + (newDate.getMonth() + 1)) : (newDate.getMonth() + 1)
				const newDay = newDate.getDate() < 10 ? ('0' + newDate.getDate()) : newDate.getDate()
				return [nowYear + '-' + nowMonth + '-' + nowDay + ' 00:00:00', newYear + '-' + newMonth + '-' + newDay +
					' 23:23:23'
				]
			},

你可能感兴趣的:(js,javascript,前端,开发语言)