我创建了一个下拉列表,其中我在15分钟的间隙中显示所有时间。
我想禁用当前服务器时间之前的所有时隙。
<?php
// print date('H:i');
//$var="abc";
//$var = date('H:i');
$time = date('G:i');
echo $time;
$start = "00:00";
$end = "23:45";
$tStart = strtotime($start);
$tEnd = strtotime($end);
$tNow = $tStart;
echo '<select name="schedule_time">';
//if($tt >= 12 && $tt <= 14){$dis = ' disabled';}else{$dis = ''}echo '<option value="wr"'.$dis.'>Washington Redskins</option>';
while($tNow <= $tEnd)
{
//if($time < $start){$tNow = 'disabled';}else{$tNow = '';} echo '<option value="'.date("H:i",$tNow).'">'.date("H:i",$tNow).'</option>';
echo '<option value="'.date("H:i",$tNow).'" disabled>'.date("H:i",$tNow).'</option>';
$tNow = strtotime('+15 minutes',$tNow);
}
echo '</select>';
?>
答案 0 :(得分:0)
您应该将时间与服务器时间进行比较,如果较小则禁用该选项。它看起来像这样:
<?php
$time = date('G:i');
$start = "00:00";
$end = "23:45";
$serverTime = strtotime($time);
$tStart = strtotime($start);
$tEnd = strtotime($end);
$tNow = $tStart;
echo '<select name="schedule_time">';
while($tNow <= $tEnd)
{
if($tNow < $serverTime) { $disable = 'disabled'; } else { $disable = ''; }
echo '<option value="'.date("H:i",$tNow).' " '.$disable.'>'.date("H:i",$tNow).'</option>';
$tNow = strtotime('+15 minutes',$tNow);
}
echo '</select>';
?>
答案 1 :(得分:0)
我认为您只需要显示future
时间下拉列表
循环value $tNow
为smaller
而不是current time strtotime(date('G:i'))
意味着你需要disable
这样。
<?php
$time = date('G:i');
echo $time;
$start = "00:00";
$end = "23:45";
$tStart = strtotime($start);
$tEnd = strtotime($end);
$tNow = $tStart;
echo '<select name="schedule_time">';
while($tNow <= $tEnd)
{
if($tNow <= strtotime(date('G:i'))){ $prop ='disabled'; }else{ $prop=''; }
echo '<option value="'.date("H:i",$tNow).'" '.$prop.'>'.date("H:i",$tNow).'</option>';
$tNow = strtotime('+15 minutes',$tNow);
}
echo '</select>';
?>