我正在开发医生预约系统,医生将首先输入它的开始时间和关闭时间,比如上午10:00到6:00 pm.If用户想要预约的医生预约,我想在30 minutes.like 10:00 - 10:30,10:30-11:0之间显示时间间隔。结束time.It将从数据库中选择开始时间和结束时间。我该怎么做?
发布于 2016-09-16 08:24:18
伪码:
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
你就是这样做的。
发布于 2016-09-16 08:21:55
您必须使用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
}
可以使用belo代码获得输出。
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
)
https://stackoverflow.com/questions/39526718
复制相似问题