特定时间和当前时间之间的差异


Difference between specific time and current time

我有一段时间使用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
}

编辑:如何找到以分钟为单位的差异,以及如何获得当前时间?

尝试先使用date()获取分钟,然后像一样进行比较

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

不确定这是否是您想要的。。。

$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";
}