我有'2013-04-10T09:00:00Z'格式的时间戳,基于此我想检查所请求的日期时间格式是否在10分钟内。
答案 0 :(得分:4)
试试这个:
$now = time();
$timestamp = strtotime('2013/04/08T09:00:00Z');
$timediff = $now - $timestamp;
if (floor($timediff/60) > 10) {
echo 'Time is 10 minutes older';
}
else {
echo 'Time is not older then 10 min';
}
答案 1 :(得分:0)
以下是我尝试的代码,它对我有用,
$currentDateTime =new DateTime();
$currentDateTime->setTimezone(new DateTimeZone('UTC'));
$userDateTime = new DateTime($timestamp); //convert users incoming
$diff = $now->diff($then);
$minutes = ($diff->format('%a')*1440)+($diff->format('%h')*60)+ ($diff->format('%i'));
if($minutes <=10)
{
//your code goes here
}
else
{
//time difference is more then 10 minutes<br/>
}
感谢Francisco为您的所有帖子。