douyue8191
2017-01-05 16:39
浏览 634
已采纳

检查是否从PHP时间戳开始经过了5分钟

I've done some research but nothing useful come out.

I need to check if a DB time stamp is -5 minutes from current time stamp. That time stamp is created with PHP time() function.

I tried with this without any luck:

$timestamp = "1451999400";

if(strtotime($timestamp) > strtotime("-5 minutes")) {
    echo "A";
} else {
    echo "B";
}

That code always returns "B".

图片转代码服务由CSDN问答提供 功能建议

我做了一些研究,但没有任何用处。

I 需要检查数据库时间戳是否距离当前时间戳-5分钟。 使用PHP time()函数创建时间戳。

我尝试过 没有任何运气:

  $ timestamp =“1451999400”; 
 
if(strtotime($ timestamp)> strtotime(“ -  5分钟”)){\  n echo“A”; 
} else {
 echo“B”; 
} 
   
 
 

该代码始终返回“B”。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dourong6054 2017-01-05 16:50
    已采纳

    First make sure, that both the database and the PHP are using the same time zone. Then:

    $timestamp = "1451999400";
    
    if($timestamp > time() - 60*5) {
        echo "A";
    } else {
        echo "B";
    }
    

    You don't need to convert the string to integer, because PHP will auto-convert it to a numeric type (possibly integer). (Because of the > operator)

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题