Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在白天隐藏过去的时光';s下降_Php - Fatal编程技术网

Php 在白天隐藏过去的时光';s下降

Php 在白天隐藏过去的时光';s下降,php,Php,我有一个下拉菜单,列出从早上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()

我有一个下拉菜单,列出从早上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>';
//time.php
日期默认时区设置(“欧洲/伦敦”);
$now=日期(“H:i”);
$start=“05:00”;
$end=“19:30”;
$tStart=strottime()>strottime($start)?strotime():strotime($start);
$tNow=$tStart;
$tEnd=STROTIME($end);
回声';

而($tNow如果已经超过9,则调整开始时间:

<?php

 // time.php
date_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){
    echo '<option value="'.date("H:i:s",$tStart).'">'.date("H:i:s",$tStart).'</option>' . PHP_EOL;
    $tStart+= 1800;
}
echo '</select>';

如果已超过9,请调整开始时间:

<?php

 // time.php
date_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){
    echo '<option value="'.date("H:i:s",$tStart).'">'.date("H:i:s",$tStart).'</option>' . PHP_EOL;
    $tStart+= 1800;
}
echo '</select>';

如果时间是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){
  $min = '30';
} else {
  $min= '00';
  $hour +=1;
  if($hour > 23){
    $hour ='00';
  }
}
$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){
    echo '<option value="'.date("H:i:s",$tNow).'">'.date("H:i:s",$tNow).'</option>';
    $tNow = strtotime('+30 minutes',$tNow);
}
echo '</select>';

如果时间是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){
  $min = '30';
} else {
  $min= '00';
  $hour +=1;
  if($hour > 23){
    $hour ='00';
  }
}
$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){
    echo '<option value="'.date("H:i:s",$tNow).'">'.date("H:i:s",$tNow).'</option>';
    $tNow = strtotime('+30 minutes',$tNow);
}
echo '</select>';

您是否尝试添加一个if()?如果时间是1:20您想在1:30或1:20开始怎么办?其次,当时间是1:50时,您想在2:00或1:50开始?好问题。它应该是:30:00,从不:20,:10:,:40等。您尝试添加一个if()吗?如果时间是1:20,你想在1:30或1:20开始怎么办?其次,当时间是1:50时,你想在2:00或1:50开始吗?好问题。应该是:30:00,从不:20,:10:,:40艾奇,我已经修改了上面的代码,但它仍然显示所有可用的下拉选项,即使是过去的下拉选项。你有一些细微的变化,所以我集成了我已经修改了上面的代码,但它仍然显示了所有可用的下拉选项,甚至是过去的下拉选项。你有一些细微的变化,所以我将这个想法整合到你的代码中。太棒了,@fiveelements。谢谢。很高兴知道它现在起作用了。如果需要,请根据你的要求更改顶部的If-else条件irement。太棒了,@fiveelements。谢谢。很高兴知道它现在起作用了。如果需要,请根据您的要求更改顶部的If-else条件。