具体时间和当前时间的区别

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