Check if timestamp is x hours old?

前端 未结 2 423
轻奢々
轻奢々 2021-01-01 18:46

Simple question, but I couldn\'t find any related topics that match this exact scenario. Everything I found involved MySQL or date and time rather than just time.

I

相关标签:
2条回答
  • 2021-01-01 19:09

    Drop the first strtotime; the variable is already in timestamp form:

    if ($ratesTimeStamp <= strtotime('-2 hours')) {
        echo "OLDER";
    } else {
        echo "not older";
    }
    
    0 讨论(0)
  • 2021-01-01 19:16
    $testedTime = 1325960262;
    $currentTime = time();
    
    if($currentTime - $testedTime > 7200){
        /// Older than 2 hours
    }
    
    0 讨论(0)
提交回复
热议问题