我想显示30分钟/的时间间隔


I want to show time interval of 30 minutes/

我正在做医生预约系统,医生会先输入其开始时间和结束时间,如上午10:00至下午6:00。如果用户想预约医生,它将根据预约。我想以30分钟为间隔显示计时。比如10点到10点半,10:30到11点。直到结束时间。它将从数据库中选择开始时间和结束时间。我该怎么做呢?

你必须使用strtotime来实现你想要的。

$starttime = '9:00';  // your start time
$endtime = '21:00';  // End time
$duration = '30';  // split by 30 mins
$array_of_time = array ();
$start_time    = strtotime ($starttime); //change to strtotime
$end_time      = strtotime ($endtime); //change to strtotime
$add_mins  = $duration * 60;
while ($start_time <= $end_time) // loop between time
{
   $array_of_time[] = date ("h:i", $start_time);
   $start_time += $add_mins; // to check endtie=me
} 

可以使用下面的代码获得输出。

echo '<pre>';
print_r($array_of_time);
echo '</pre>';

以上代码的输出将如下所示:

Array
(
    [0] => 09:00
    [1] => 09:30
    [2] => 10:00
    [3] => 10:30
    [4] => 11:00
    [5] => 11:30
    [6] => 12:00
    [7] => 12:30
    [8] => 01:00
    [9] => 01:30
    [10] => 02:00
    [11] => 02:30
    [12] => 03:00
    [13] => 03:30
    [14] => 04:00
    [15] => 04:30
    [16] => 05:00
    [17] => 05:30
    [18] => 06:00
    [19] => 06:30
    [20] => 07:00
    [21] => 07:30
    [22] => 08:00
    [23] => 08:30
    [24] => 09:00
)

伪代码:

do connection to database
get result from database with start and endtime
new array
while startTime is not equal to endTime
    startTime + 30 minutes
    insert into array startTime 
while end
generate selectbox with array values
show selectbox

你可以这样做