可以使用Date对象和for循环来生成一个包含时间范围内所有时间的数组。具体实现如下:
function generateTimeArray(startTime, endTime) {
let result = [];
let start = new Date(startTime);
let end = new Date(endTime);
// 添加1分钟间隔的时间
for (let current = start; current <= end; current.setMinutes(current.getMinutes() + 1)) {
result.push(current.toTimeString().substr(0, 5));
return result;
// 示例
let startTime = "2022-01-01 00:00:00";
let endTime = "2022-01-01 00:10:00";
console.log(generateTimeArray(startTime, endTime)); // ["00:00", "00:01", "00:02", "00:03", "00:04", "00:05", "00:06", "00:07", "00:08", "00:09", "00:10"]