繁体   English   中英

我如何在if / else PHP语句中解释时间?

[英]How would I interpret time in an if/else PHP statement?

$currentTime = date("Hi");

if($currentTime > 0559 && $currentTime < 1401) {
     // Stuff here
}

那是我当前的代码,但是if语句似乎在午夜之后的任何时间运行,而不仅仅是在0600(当地时间上午6:00)之后运行。 任何想法会导致这种情况。

In (if($currentTime > 0559) -由于前面有0因此将0559视为octal

只需在比较中将其删除if($currentTime > 559)

您使用的整数与您认为的其他方式不同,请在此处查看integer文档

$a = 0123; // octal number (equivalent to 83 decimal)

让我们回到您的代码,要修复它,只需在整数之前删除0 ,这样它就不会解释为octal ,只需更改为

if(($currentTime > 559) && ($currentTime < 1401)) {
    // Stuff here
}

确保您使用的是整数。

$currentTime = intval( date("Hi") );

if ($currentTime > 559 && $currentTime < 1401) {
    // Stuff here
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM