获取最近一个月的时间

function getMonth() {

            let date1 = new Date();  // 获取当前日期

            let arr = [];

            for(let i=0; i<30; i++){

                let date2 = new Date(date1);

                date2.setDate(date1.getDate() + i);

                let dayYear = date2.getFullYear();

                let dayMon = (date2.getMonth() + 1)< 10 ?'0'+(date2.getMonth() + 1):(date2.getMonth() + 1);

                let dayDate = date2.getDate() < 10 ?'0'+ date2.getDate():date2.getDate();

                let dayList = dayYear+ "/" + dayMon + "/"+ dayDate;

                arr.push(dayList);  // 存储日期

            }

            let  hour = date1.getHours();

            let  min = date1.getMinutes() < 10 ?'0'+ date1.getMinutes() : date1.getMinutes();

            let hourMin = hour+":"+min;

            let arr2 = [];

            arr2.push(arr);

            arr2.push(hourMin);

          return arr2;    // [arr(30),"15:15"] 

          //arr = ["2018/10/30","2018/10/31","2018/11/01",……,"2018/11/28",];30天

          // 15:15 当前时间

}

你可能感兴趣的:(获取最近一个月的时间)