传入开始和结束时间 例如getTimeList(‘00:00’, ‘02:00’), 会得到[‘00:00’, ‘00:30’, ‘01:00’, ‘01:30’, ‘02:00’]
getTimeList(startTime, endTime) {
let times = [];
let startHour = parseInt(startTime.split(':')[0]);
let startMinute = parseInt(startTime.split(':')[1]);
let endHour = parseInt(endTime.split(':')[0]);
let endMinute = parseInt(endTime.split(':')[1]);
for (let hour = startHour; hour <= endHour; hour++) {
let minuteStart = (hour === startHour) ? Math.ceil(startMinute / 30) * 30 : 0;
let minuteEnd = (hour === endHour) ? Math.floor(endMinute / 30) * 30 + 30 : 60;
for (let minute = minuteStart; minute < minuteEnd; minute += 30) {
let time = ('0' + hour).slice(-2) + ':' + ('0' + minute).slice(-2);
times.push(time);
}
}
return times
}