나는 select 입력에서 일련의 옵션을 제공하는이 함수를 가지고있다. 옵션은 5 분 간격으로 시간을 알려줍니다. 문제는 시간이 23:45와 같을 때 옵션이 00:10부터 시작하여 $ j 변수를 기반으로 반복됩니다.PHP 시작 시간과 종료 시간 사이의 시간 루프
이것은 단어로하고 싶습니다. $ open_time에서 $ close_time까지 5 분 간격으로 옵션 목록을 제공하십시오. 현재 시간 ($ timeNow)이 $ open_time보다 큰 경우 $ open_time을 $ timeNow로 설정하여 첫 번째 옵션으로 표시합니다. 이 루프는 $ close_time까지만 수행하십시오.
분명히하는 것이 좋겠습니다.
function selectTimesofDay(){
$output = "";
$now = date('G:i ', time()); // time now
$timeNow = strtotime($now); // strtotime now
$next_five = ceil($timeNow/300) * 300; // get next 5 minute
// time now rounded to next 10 minute
$round5minNow = date('G:i', strtotime('+15 minutes',$next_five));
$open_time = strtotime('17:00');
$close_time = strtotime('23:59');
// in the middle of working hours, time sets to current
if($timeNow >= $open_time && $timeNow < $close_time){
$open_time = strtotime($round5minNow);
}
$time_diff = round(($close_time - $open_time)/60) ;
if(date('l') == 'Friday'){
$j = ($time_diff/5)+11; // working hours extended untill 1:00 AM
} else{
$j = ($time_diff/5)-1; // working hours untill 12:00 AM
}
for($i = 0; $i <= $j; $i++){
$b = $i*5;
$data = date('l')." - ".date("H:i", strtotime('+'.$b.' minutes', $open_time));
$output .= "<option value=\"{$data}\">";
$output .= $data;
$output .= "</option>";
}
return $output;
}
위 코드가 잘못된 이유는 무엇입니까? –
클라이언트 컴퓨터의 시간이 23:45처럼되면 옵션 세트는 00:15부터 시작하여 23:55까지 계속됩니다! –