根据当前系统时间自动生成输入值
问题描述:
I am creating a production recording system. What I want is that to automatically generate the input in "hour" based on the current system time. For example if the system time is in between 7.00 am and 7.15 am, the "hour" should be 1.Like that it should continue. I have written the following code but seems like it is wrong.Can anyone give me suggestions for that?
<?php
$sql="SELECT CURTIME() AS Time";
$result=mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result)){
$time=$row['Time'];
}
if("07:00:00"<="$time"<="07:15:00"){
echo "<input class='form-control' type='text' name='hour' value='1' readonly >";
}
?>
我正在创建一个制作录制系统。 我想要的是根据当前系统时间以“小时”自动生成输入。 例如,如果系统时间在早上7点到早上7点15分之间,那么“小时”应该是1.就像它应该继续一样。 我写了下面的代码,但似乎是错的。任何人都可以给我建议吗? p>
&lt;?php
$ sql =“SELECT CURTIME()AS 时间“;
$ result = mysqli_query($ conn,$ sql);
while($ row = mysqli_fetch_array($ result)){
$ time = $ row ['Time'];
} \ n if(“07:00:00”&lt; =“$ time”&lt; =“07:15:00”){
echo“&lt; input class ='form-control'type ='text'name = 'hour'value ='1'readonly&gt;“;
}
?n&gt;
code> pre>
div>
答
It's probably easiest to manipulate times using timestamps. You can set the start and end times and then do a simple conditional to display the form element you want to display.
$current_time = time();
$start = strtotime("07:00:00");
$end = strtotime("07:15:00");
if ($current_time > $start && $current_time < $end)
{
echo "<input class='form-control' type='text' name='hour' value='1' readonly >";
}
答
I found another solution which helped me
<?php
date_default_timezone_set("Asia/Colombo");
$current_time=date('H:i:s', time());
$time1 ="06:00:00";
$time2 ="07:15:00";
if ($current_time > $time1 && $current_time < $time2)
{
echo "<input class='form-control' type='text' name='hour' value='1' readonly >";
}
<?