您可以使用strtotime()进行时间计算。这是一个例子:
$checkTime = strtotime('09:00:59');echo 'Check Time : '.date('H:i:s', $checkTime);echo '<hr>';$loginTime = strtotime('09:01:00');$diff = $checkTime - $loginTime;echo 'Login Time : '.date('H:i:s', $loginTime).'<br>';echo ($diff < 0)? 'Late!' : 'Right time!'; echo '<br>';echo 'Time diff in sec: '.abs($diff);echo '<hr>';$loginTime = strtotime('09:00:59');$diff = $checkTime - $loginTime;echo 'Login Time : '.date('H:i:s', $loginTime).'<br>';echo ($diff < 0)? 'Late!' : 'Right time!';echo '<hr>';$loginTime = strtotime('09:00:00');$diff = $checkTime - $loginTime;echo 'Login Time : '.date('H:i:s', $loginTime).'<br>';echo ($diff < 0)? 'Late!' : 'Right time!';演示版
查看已经提出的问题- 如何以分钟为单位获取时差:
从过去的一减去最近的一并除以60。
时间以Unix格式完成,因此它们只是一个很大的数字,显示了格林尼治标准时间1970年1月1日00:00:00起的秒数


![在PHP中获得两次之间的时差[重复] 在PHP中获得两次之间的时差[重复]](http://www.mshxw.com/aiimages/31/421082.png)
