在一天的下拉菜单中隐藏过去的时间

我有一个下拉菜单,列出了从上午 9 点到晚上 7:30 的所有时间。


如果是下午 1 点,我只想显示诸如下午 1:30、下午 2 点等选项。


如何使用我当前的代码实现这一目标?谢谢你。


 // time.php

date_default_timezone_set('Europe/London');


$now = date("H:i");

$start = "05:00";

$end = "19:30";


$tStart = strtotime() > strtotime($start) ? strtotime() : strtotime($start);


$tNow = $tStart;

$tEnd = strtotime($end);


echo '<select name="schedule_time">';

while($tNow <= $tEnd){

    echo '<option value="'.date("H:i:s",$tNow).'">'.date("H:i:s",$tNow).'</option>';

    $tNow = strtotime('+30 minutes',$tNow);

}

echo '</select>';


SMILET
浏览 104回答 2
2回答

噜噜哒

如果时间是 1:20,您想从 1:30 或 1:20 开始怎么办?其次,当是 1:50 时,您想在 2:00 还是 1:50 开始?我假设您想在这两个示例中从 1:30 和 2:00 开始:<?php$hour = date('H');$min = date('i');echo 'Current time '.$hour.':'.$min;if($min <=30){&nbsp; $min = '30';} else {&nbsp; $min= '00';&nbsp; $hour +=1;&nbsp; if($hour > 23){&nbsp; &nbsp; $hour ='00';&nbsp; }}$start = $hour.':'.$min;echo 'Modified time '.$start;$end = "19:30";$tStart = strtotime($start);$tEnd = strtotime($end);$tNow = $tStart;echo '<select name="schedule_time">';while($tNow <= $tEnd){&nbsp; &nbsp; echo '<option value="'.date("H:i:s",$tNow).'">'.date("H:i:s",$tNow).'</option>';&nbsp; &nbsp; $tNow = strtotime('+30 minutes',$tNow);}echo '</select>';

慕慕森

如果已经过了 9 点,请调整您的开始时间:<?php&nbsp;// time.phpdate_default_timezone_set('Europe/London');$start = "05:00";$end = "19:30";$now = time();// Normalize Now to next 1/2 hour$now = ($now - ($now % 1800)) + 1800;$tStart = $now > strtotime($start) ? $now : strtotime($start);$tEnd = strtotime($end);echo '<select name="schedule_time">' . PHP_EOL;while($tStart <= $tEnd){&nbsp; &nbsp; echo '<option value="'.date("H:i:s",$tStart).'">'.date("H:i:s",$tStart).'</option>' . PHP_EOL;&nbsp; &nbsp; $tStart+= 1800;}echo '</select>';
打开App,查看更多内容
随时随地看视频慕课网APP