2013-04-08 161 views

回答

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/> 
} 

舊金山感謝您的所有職務。

3

試試這個:

$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'; 
} 
+2

似乎條件中的$ datediff應該是'$ timediff'或其他方式。 – Rikesh 2013-04-08 05:25:09

+0

很好的發現,謝謝。固定。 – 2013-04-08 05:29:04

+0

即使我的時間不長,它總是給我留言「時​​間不再大於10分鐘」。這是時區問題嗎?我編輯了我的$ timestamp = strtotime('2013/04/08T11:30:00Z');目前我的時間是11:32:00。 – amol 2013-04-08 06:01:09

相關問題