我在$user_timestamp中存储了一个特定的时间戳,例如,1421942631。我把当前的时间戳存储在$current_timestamp中。
我想比较这个变量中的时间戳和当前时间戳,并检查它是否已经运行了3天。如果有,那就行动起来。
如何在基本的if语句中做到这一点?
发布于 2015-01-22 16:10:35
虽然我通常建议使用DateTime来计算日期,但是您可以只使用相对格式和strtotime()来保持简单。
if($user_timestamp < strtotime('-3 days')) {
// three days ago or more
}但是为了完整起见,这里是DateTime示例。
$userTimestamp = new DateTime('@'.$user_timestamp);
$threeDaysAgo = new DateTime('-3 days');
if ($userTimestamp < $threeDaysAgo) {
// three days ago or more
}发布于 2015-01-22 16:19:42
不需要转换它或使用其他函数。3天= 259200秒,所以应该可以:
if( $user_timestamp < ( $current_timestamp-259200 ) ){https://stackoverflow.com/questions/28093430
复制相似问题