本文主要是介绍js获取当前日期与7天后的日期,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
调用
console.log(this.getSectionData(7))
结果
函数
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获取当前日期与7天后的日期的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!