Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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
使用日期(“H”);定义PHP的步骤_Php - Fatal编程技术网

使用日期(“H”);定义PHP的步骤

使用日期(“H”);定义PHP的步骤,php,Php,我想要实现的是让一个div在一个设定的时间出现,我已经实现了(GoMe),我的问题是我当前的代码我只能以小时为单位设置时间。我希望能够以小时/分钟为单位进行设置 例如,使div在上午9点到10:30之间出现。(目前,我只能将其显示在“小时”上,例如上午9点到10点。) 下面是我设置时间的地方: date_default_timezone_set('Europe/London'); $currentHour = date("H"); $day = date("1"); $nineAlertStar

我想要实现的是让一个div在一个设定的时间出现,我已经实现了(GoMe),我的问题是我当前的代码我只能以小时为单位设置时间。我希望能够以小时/分钟为单位进行设置

例如,使div在上午9点到10:30之间出现。(目前,我只能将其显示在“小时”上,例如上午9点到10点。)

下面是我设置时间的地方:

date_default_timezone_set('Europe/London');
$currentHour = date("H");
$day = date("1");
$nineAlertStart = 9;
$nineAlertEnd = 10;
以下是在设定时间显示div的功能:

if ($currentHour >= $nineAlertStart && $currentHour < $nineAlertEnd){
          // If we are, set our class to off.
        $ninealert = 'timeOn';
  } else {
        // Otherwise, set our class to off.
        $ninealert = 'timeOff';
  }
如果($currentHour>=$nineAlertStart&&$currentHour<$nineAlertEnd){
//如果是的话,就让我们的课开始。
$ninealert='timeOn';
}否则{
//否则,请将我们的课程设置为“关”。
$ninealert='timeOff';
}
最后是我要显示的输出

<div class="alert <?php echo $ninealert; ?>">
    Jade
</div>

尝试以下方法,看看是否适合您

date_default_timezone_set('Europe/London');
$currentTime = date("Gi");
$day = date("1");
$nineAlertStart = 900;
$nineAlertEnd = 1030;

if ($currentTime >= $nineAlertStart && $currentTime < $nineAlertEnd){
      // If we are, set our class to off.
    $ninealert = 'timeOn';
} else {
    // Otherwise, set our class to off.
    $ninealert = 'timeOff';
}
date\u default\u timezone\u set(“欧洲/伦敦”);
$currentTime=日期(“Gi”);
$day=日期(“1”);
$nineAlertStart=900;
$nineAlertEnd=1030;
如果($currentTime>=$nineAlertStart&$currentTime<$nineAlertEnd){
//如果是的话,就让我们的课开始。
$ninealert='timeOn';
}否则{
//否则,请将我们的课程设置为“关”。
$ninealert='timeOff';
}
您可以尝试以下方法:

date_default_timezone_set('Europe/London');

$currentHour = microtime(true);

$day = date("1");

$nineAlertStart = strtotime("09:09:09");
$nineAlertEnd = strtotime("10:30:00");

if ($currentHour >= $nineAlertStart && $currentHour < $nineAlertEnd){
      // If we are, set our class to off.
    $ninealert = 'timeOn';
} else {
    // Otherwise, set our class to off.
    $ninealert = 'timeOff';
 }



<div class="alert <?php echo $ninealert; ?>">
Jade
</div>
date\u default\u timezone\u set(“欧洲/伦敦”);
$currentHour=微时间(真);
$day=日期(“1”);
$nineAlertStart=strottime(“09:09:09”);
$nineAlertEnd=标准时间(“10:30:00”);
如果($currentHour>=$nineAlertStart&$currentHour<$nineAlertEnd){
//如果是的话,就让我们的课开始。
$ninealert='timeOn';
}否则{
//否则,请将我们的课程设置为“关”。
$ninealert='timeOff';
}

试着用date('i')来简化这个过程;日期(“H i”);对于小时和分钟
date('Gi')>=900&&date('Gi')顺便说一句,
date(“1”)
什么都不做,你可以只做
$day=“1”
。我会使用格式
Gi
(无前导零)来避免任何隐式的八进制转换。谢谢你-我知道这是“I”中的一些东西,但我无法完全围绕它动脑