js 13位时间戳数组,求出五分钟倍数的时间戳数组,数据是2022-01-01 00:22:22 到2023-07-01 00:02:12 最后数组是日期格式
时间: 2024-04-09 16:29:06 浏览: 8
您好!以下是在JavaScript中实现根据给定时间范围生成五分钟倍数时间戳数组的代码:
```javascript
const startTimestamp = new Date('2022-01-01 00:22:22').getTime();
const endTimestamp = new Date('2023-07-01 00:02:12').getTime();
const timestamps = [];
let currentTimestamp = startTimestamp;
while (currentTimestamp <= endTimestamp) {
const currentDatetime = new Date(currentTimestamp);
if (currentDatetime.getMinutes() % 5 === 0) {
const formattedDate = currentDatetime.toISOString().replace(/T|Z/g, ' ').trim();
timestamps.push(formattedDate);
}
currentTimestamp += 60000; // 增加一分钟的时间戳(毫秒为单位)
}
console.log(timestamps);
```
这段代码会生成从2022-01-01 00:22:22到2023-07-01 00:02:12期间,五分钟倍数的时间戳数组,并将其格式化为日期字符串。输出结果将会是一个包含符合条件的日期格式时间戳的数组。希望对您有所帮助!如果有任何其他问题,请随时提问。