我有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 :(得分:2)
首先尝试使用date()
获得分钟,然后比较
$sp_time = 1400325952;//Specific time
$currentTime = time(); // current time
$difference = $currentTime - $sp_time;
if(date('i',$difference) >= '5') {
//DO SOME STUFF
}
答案 1 :(得分: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";
}