我已经看过this的问题,而是时间的格式是不同的PHP的日期和时间比较
我有以下日期格式Tue, 11 Sep 2012 17:38:09 GMT
在$pubDate
可变
我想比较$pubDate
与当前日期和时间看如果Tue, 11 Sep 2012 17:38:09 GMT
是在最后10分钟或不
编辑:
我已经试过
//get current time
strtotime($pubDate);
time() - strtotime($pubDate);
if((time()-(60*10)) < strtotime($pubDate)){
//if true increase badge by one
$badge = $badge + 1;
}
它给出警告: 依靠系统的时区设置是不安全的。您需要需要才能使用date.timezone设置或date_default_timezone_set()函数。如果您使用这些方法中的任何一种,并且仍然收到此警告,则很可能是拼写错误的时区标识符。我们选择 '美国/纽约' 的 'EDT/-4.0/DST',而不是在/Users/xxxxx/Desktop/xxxx/xxxx/xxxx.php在线26
编辑:
我已经加入date_default_timezone_set('America/New_York');
线我的PHP和现在
$inDate = DateTime::createFromFormat($format, $pubDate);
$postDate = new DateTime();
$diff = $inDate->diff($postDate);
// If the total number of days is > 0, or the number of hours > 0, or the number of minutes > 10, then its an invalid timestamp.
if($diff->format('%a') > 0 || $diff->format('%h') > 0 || $diff->format('%i') > 10) {
die('The timestamps differ by more than 10 minutes');
}
作品没有警告,谢谢大家
我编辑过问题 –
那么......你是否调用了'date_default_timezone_set()'函数呢? – verdesmarald
另一方面,如果您比较'strtotime($ pubDate)'到'strtotime(' - 10分钟')'',则会更容易... ... – Havelock