我正在创建一个预约系统。自动创建10乘10的时间,但我需要从24小时日期时间系统中删除午餐时间,即13:00之间的12:00。
$start=strtotime("08:30");
$end=strtotime("17:30");
$now=$start;
while($now <= $end){
echo '<option value="'.date("H:i",$now).':00">'.date("H:i",$now).'</option>';
$now = strtotime('+10 minutes',$now);
}
只需添加午餐时间:
$start=strtotime("08:30");
$end=strtotime("17:30");
$startLunch=strtotime("12:00");
$endLunch=strtotime("13:00");
$now = $start;
// and then you can use it in your while loop:
while($now <= $end){
if($now < $startLunch || $now > $endLunch)
{
echo '<option value="'.date("H:i",$now).':00">'.date("H:i",$now).'</option>';
}
$now = strtotime('+10 minutes',$now);
}
试试这个:
$start=strtotime("08:30");
$end=strtotime("17:30");
$lunch_start=strtotime("12:00");
$lunch_end=strtotime("13:00");
$now=$start;
while(($now <= $end) && ($now >= $lunch_start || $now <= $lunch_end)){
echo '<option value="'.date("H:i",$now).':00">'.date("H:i",$now).'</option>';$now = strtotime('+10 minutes',$now);
}