我想创建一个时间段,从上午10:00到下午7:00允许预订。
条件:每个服务时间60分钟& 0分钟休息。 喜欢这个,
上午10:00 - 上午11:00
上午11:00 - 凌晨12:00
12:00 AM - 13:00 AM
13:00 AM - 14:00 PM
你们能为我提供这个问题的解决方案吗?提前谢谢。
答案 0 :(得分:2)
试试这个......
function getServiceScheduleSlots($duration, $start,$end)
{
$start = new DateTime($start);
$end = new DateTime($end);
$start_time = $start->format('H:i');
$end_time = $end->format('H:i');
$i=0;
while(strtotime($start_time) <= strtotime($end_time)){
$start = $start_time;
$end = date('H:i',strtotime('+'.$duration.' minutes',strtotime($start_time)));
$start_time = date('H:i',strtotime('+'.$duration.' minutes',strtotime($start_time)));
$i++;
if(strtotime($start_time) <= strtotime($end_time)){
$time[$i]['start'] = $start;
$time[$i]['end'] = $end;
}
}
return $time;
}
$slopt = getServiceScheduleSlots(60, '10:00AM', '07:00PM')
结果将如下:
Array
(
[1] => Array
(
[start] => 10:00
[end] => 11:00
)
[2] => Array
(
[start] => 11:00
[end] => 12:00
)
[3] => Array
(
[start] => 12:00
[end] => 13:00
)
[4] => Array
(
[start] => 13:00
[end] => 14:00
)
[5] => Array
(
[start] => 14:00
[end] => 15:00
)
[6] => Array
(
[start] => 15:00
[end] => 16:00
)
[7] => Array
(
[start] => 16:00
[end] => 17:00
)
[8] => Array
(
[start] => 17:00
[end] => 18:00
)
[9] => Array
(
[start] => 18:00
[end] => 19:00
)
)