有时候我们需要使用时间来给用户做一些限制,比如特权到期。下面是常用的时间计算方法。
复制
<?php
$one = strtotime('2015-12-08 07:02:40');//开始时间 时间戳
$tow = strtotime('2016-05-21 00:00:00');//结束时间 时间戳
$cle = $tow - $one; //得出时间戳差值
$d = floor($cle/3600/24);
$h = floor(($cle%(3600*24))/3600); //%取余
$m = floor(($cle%(3600*24))%3600/60);
$s = floor(($cle%(3600*24))%60);
echo "两个时间相差 $d 天 $h 小时 $m 分 $s 秒"
?>效果如下图:
时间的比较:
时间类型比较时,使用时间戳可以很方便的比较谁比谁早,将datetime类型转换为时间戳类型的函数是strtotime
使用方法:
复制
strtotime('2015-12-08 07:02:40');






评论 (1)