简体   繁体   English

大于/小于BOTH的PHP运算符在相同的数字上触发

[英]PHP Operators for Greater/Less than BOTH triggered on same numbers

Trying to add a simple X minute timer to an order status. 尝试将简单的X分钟计时器添加到订单状态。 I'm doing this by setting the timezone, loading the current UNIX time into a variable, then adding X minutes for a trigger time. 我这样做是通过设置时区,将当前UNIX时间加载到变量中,然后为触发时间添加X分钟。 Every time the page loads, it checks the stored "trigger" time and compares it to the current time. 每次加载页面时,它都会检查存储的“触发”时间并将其与当前时间进行比较。 If the current timestamp is larger than the stored one, move on to the next step. 如果当前时间戳大于存储的时间戳,请继续执行下一步。 The next step happens regardless of the "now" being less than "overtime". 无论“现在”是否小于“加班”,下一步都会发生。

$now = (int) time(); //1550450927
$overtime = strtotime(+5 minutes); //1550451222

//also tried datetime format
$now = new DateTime('now');
$overtime = $now->modify('+10 Minutes');

if ( $now >= $overtime ) { //if "overtime" has passed

 //stuff happens with no regard for reality
 //driving me absolutely bonkers

}

Checking the database inputs of current times compared to requested times, everything is correct with the numbers. 检查数据库输入的当前时间与请求的时间相比,数字的一切都是正确的。 They are being stored exactly as the examples given, UNIX timestamps. 它们的存储方式与给定的示例一致,即UNIX时间戳。

Calling modify() is updating the $now value as well as the $overtime value. 调用modify()会更新$now值以及$overtime值。

Also, this may be of interest to you How do I deep copy a DateTime object? 此外,您可能会对此感兴趣如何深度复制DateTime对象?

Try: 尝试:

$now = (int) time(); //1550450927
$overtime = strtotime("+5 minutes"); //1550451222

//also tried datetime format
$now = new DateTime('now');
$overtime = (new DateTime("now"))->modify("+5 minutes");
print_r($now);
print_r($overtime);
if ( $now >= $overtime ) { //if "overtime" has passed
echo "hit";
 //stuff happens with no regard for reality
 //driving me absolutely bonkers

}

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

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