簡體   English   中英

大於/小於BOTH的PHP運算符在相同的數字上觸發

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

嘗試將簡單的X分鍾計時器添加到訂單狀態。 我這樣做是通過設置時區,將當前UNIX時間加載到變量中,然后為觸發時間添加X分鍾。 每次加載頁面時,它都會檢查存儲的“觸發”時間並將其與當前時間進行比較。 如果當前時間戳大於存儲的時間戳,請繼續執行下一步。 無論“現在”是否小於“加班”,下一步都會發生。

$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

}

檢查數據庫輸入的當前時間與請求的時間相比,數字的一切都是正確的。 它們的存儲方式與給定的示例一致,即UNIX時間戳。

調用modify()會更新$now值以及$overtime值。

此外,您可能會對此感興趣如何深度復制DateTime對象?

嘗試:

$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