const checkList = ['9:00-10:00', '10:30-11:30', '13:00-14:00', '14:30-15:30', '16:00-17:00']; 定义一个函数求出两两相邻的时间戳
时间: 2024-04-15 09:30:35 浏览: 15
您可以定义一个函数来计算两两相邻的时间戳。以下是一个示例代码:
```javascript
const checkList = ['9:00-10:00', '10:30-11:30', '13:00-14:00', '14:30-15:30', '16:00-17:00'];
function calculateAdjacentTimestamps(timeList) {
const timestamps = [];
for (let i = 0; i < timeList.length - 1; i++) {
const currentTime = timeList[i];
const nextTime = timeList[i + 1];
const currentTimestamp = currentTime.split('-')[1];
const nextTimestamp = nextTime.split('-')[0];
timestamps.push([currentTimestamp, nextTimestamp]);
}
return timestamps;
}
const adjacentTimestamps = calculateAdjacentTimestamps(checkList);
console.log(adjacentTimestamps);
```
这段代码将计算出两两相邻的时间戳,并将结果存储在`adjacentTimestamps`数组中。输出结果为`[['10:00', '10:30'], ['11:30', '13:00'], ['14:00', '14:30'], ['15:30', '16:00']]`。
请注意,这里假设时间范围的终止时间和下一个时间范围的起始时间是紧密相连的,没有重叠或间隔。如果输入的时间格式不一致或不满足这些条件,可能需要进行额外的验证和处理。