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

编程入门 行业动态 更新时间:2024-10-13 02:18:16

js获取当前<a href=https://www.elefans.com/category/jswz/34/1771397.html style=日期与7天后的日期"/>

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天后的日期

本文发布于:2023-11-15 20:02:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   天后   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!