2015-02-10 42 views
0

那麼我有一個UNIX格式的時間。我需要找出特定時間和當前時間之間的差異。如果差異是5分鐘。做一點事。具體時間和當前時間的差異

$sp_time = 1400325952;//Specific time 
$currentTime = //current time in UNIX format 

$difference = $currentTime - $sp_time; 
if($difference >= 5)//if difference is less than or equal to 5minutes 
{ 
    //DO SOME STUFF 
} 

編輯:如何在幾分鐘內找到差異以及如何獲得當前時間?

+0

請告訴我你的問題就在這裏?描述你的問題/錯誤。 – 2015-02-10 05:37:56

回答

2

嘗試先獲取分鐘使用date()則比較喜歡

$sp_time = 1400325952;//Specific time 
$currentTime = time(); // current time 
$difference = $currentTime - $sp_time; 
if(date('i',$difference) >= '5') { 
    //DO SOME STUFF 
} 
1

不知道這是你在找什麼...

$sp_time = 1400325952;//Specific time 
$currentTime = time(); // current time 
$diff = abs($currentTime - $sp_time); 

$mins = round($diff/60); 

if ($mins <= 5) { 
echo "difference is less than or equal to 5minutes: $mins"; 
} 
相關問題