标签:date() ring rtt console while art turn string pre
var start = "2019-02-11";//开始时间 var end = nowTime();//结束时间 //返回当前时间 function nowTime(){ var now = new Date(); var year = now.getFullYear(); var month = now.getMonth() + 1; var date = now.getDate(); if(month<10){ month = "0" + month; } if(date<10){ date = "0" + date; } return year + "-" + month + "-" +date; } //返回日期数组 function timeArr(start,end){ var date = [],i = 0; function getDate(datestr){ var temp = datestr.split("-"); var date = new Date(temp[0],temp[1]-1,temp[2]); // console.log(date); return date; } var startTime = getDate(start); var endTime = getDate(end); while((endTime.getTime()-startTime.getTime())>=0){ var year = startTime.getFullYear(); var month = (startTime.getMonth()+1).toString().length==1?"0"+(startTime.getMonth()+1).toString():(startTime.getMonth()+1).toString(); var day = startTime.getDate().toString().length==1?"0"+startTime.getDate():startTime.getDate(); date[i]=year+"-"+month+"-"+day; startTime.setDate(startTime.getDate()+1); i+=1; } return date; } //结果 var date = timeArr(start,end); console.log(date)
标签:date() ring rtt console while art turn string pre
原文地址:https://www.cnblogs.com/rain101/p/12149731.html