js獲取當前日期到接下來的一周日期的日期數組


 

 

  <script type="text/javascript">
        // 獲取當前日期的之后六天日期  日期格式2020-07-23
        var today=new Date();
        var dateArr=[]
        for(var i=0;i<7;i++){
            var newDate=new Date(today.getTime()+i*1000*60*60*24)
            var year=newDate.getFullYear()
            var month=(parseInt(newDate.getMonth())+1)>9?(parseInt(newDate.getMonth())+1):"0"+(parseInt(newDate.getMonth())+1)
            var day=(newDate.getDate())>9?newDate.getDate():"0"+newDate.getDate()
            var fullDate=`${year}-${month}-${day}`
            dateArr.push(fullDate)
        }
        console.log(dateArr)
    </script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM