您可以使用
strtotime()进行时间计算。这里是一个例子:
$checkTime = strtotime('09:00:59');
echo 'Check Time : '.date('H:i:s', $checkTime);
echo '
';
$loginTime = strtotime('09:01:00');
$diff = $checkTime - $loginTime;
echo 'Login Time : '.date('H:i:s', $loginTime).'
';
echo ($diff < 0)? 'Late!' : 'Right time!'; echo '
';
echo 'Time diff in sec: '.abs($diff);
echo '
';
$loginTime = strtotime('09:00:59');
$diff = $checkTime - $loginTime;
echo 'Login Time : '.date('H:i:s', $loginTime).'
';
echo ($diff < 0)? 'Late!' : 'Right time!';
echo '
';
$loginTime = strtotime('09:00:00');
$diff = $checkTime - $loginTime;
echo 'Login Time : '.date('H:i:s', $loginTime).'
';
echo ($diff < 0)? 'Late!' : 'Right time!';
Subtract the past-most one from the future-most one and divide by 60.
Times are done in unix format so they’re just a big number showing the number of seconds from January 1 1970 00:00:00 GMT