共计 540 个字符,预计需要花费 2 分钟才能阅读完成。
function getDuration(type,start,stop){var $array = new Array();
var current = new Date(start);
stop = new Date(stop);
while (current <= stop) {$array.push( new Date (current) );
if(type == 'hour'){// 小时
current.setHours(current.getHours() + 1);
}else if(type == 'day'){// 天
current.setDate(current.getDate() + 1);
}else if(type == 'week'){// 周
current.setDate(current.getDate() + 7);
}else if(type == 'month'){// 月
current.setMonth(current.getMonth() + 1);
}else{// 默认天
current.setDate(current.getDate() + 1);
}
}
return $array;
}
console.log(getDuration('day','2019-10-05 10:23:16','2019-11-05 18:23:16'));
正文完