构建 分钟 构建天 构建 月份
构建分钟 相隔5分钟
function buildMinutes(){
var a=[];
for(var x=0;x<24;x++){
if(x<10){
x="0"+x
}
x=x+""
a.push(x)
}
var b=[]
for(var i=0;i<12;i++){
var n=i;
var m=n*5
if(m<10){
m="0"+m
}
b.push(m+"");
}
var minute=[]
for(var j=0;j<a.length;j++){
for(var k=0;k<b.length;k++){
minute.push(a[j]+b[k]);
}
}
return minute
}
console.log(buildMinutes())
//构建天
function buildDay (num) {
num = num - 1;
var myDate = new Date(this.pubTime); //获取今天日期
myDate.setDate(myDate.getDate() - num);
var dateArray = [];
var dateTemp;
var flag = 1;
for (var i = 0; i < num; i++) {
var month = myDate.getMonth() + 1
if (month < 10) {
month = "0" + month;
}
var day = myDate.getDate()
if (day < 10) {
day = "0" + day;
}
dateTemp = myDate.getFullYear() + "" + month + "" + day;
dateArray.push(dateTemp);
myDate.setDate(myDate.getDate() + flag);
}
dateArray.push(this.pubTime.replace(/-/g, ""))
return dateArray
}
//构建月份
function buildMonth(months) {
var now = new Date(this.pubTime);
var cur_month = now.getMonth();
now.setDate(1);//重置成1号,原因:在做减月份时,减去的月份没有31号,会自动加1到下个月份,导致计算失误
if (months < 0) {
var _m = cur_month + months + 1;
now.setMonth(_m);
}
var _months = [];
for (var i = 0; i < Math.abs(months); i++) {
var year = now.getFullYear();
var month = now.getMonth();
if (i != 0) {
now.setMonth(month + 1);
}
year = now.getFullYear();
var _month = now.getMonth() + 1;
if (_month < 10) _month = '0' + _month;
else _month = _month.toString();
_months.push(year + _month);
}
return _months;
}
请爱好前端技术的朋友,联系我,有问题大家一起讨论