我有一个 '2013-04-10T09:00:00Z' 格式的时间戳,基于此我想检查请求的日期时间格式是否在 10 分钟内。
问问题
2420 次
2 回答
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';
}
于 2013-04-08T05:23:55.023 回答
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/>
}
感谢弗朗西斯科的所有帖子。
于 2013-08-12T11:24:58.573 回答