计算两个日期相差 年 月 日
相差年月日计算
DiffDate("2011-01-06","2015-06-16");/** <br>
+---------------------------------------------------------- <br>
* 功能:计算两个日期相差 年 月 日 <br>
+---------------------------------------------------------- <br>
* @param date $date1 起始日期 <br>
* @param date $date2 截止日期日期 <br>
+---------------------------------------------------------- <br>
* @return array <br>
+---------------------------------------------------------- <br>
*/<br>
function DiffDate($date1, $date2) { <br>
if (strtotime($date1) > strtotime($date2)) { <br>
$ymd = $date2; <br>
$date2 = $date1; <br>
$date1 = $ymd; <br>
} <br>
list($y1, $m1, $d1) = explode('-', $date1); <br>
list($y2, $m2, $d2) = explode('-', $date2); <br>
$y = $m = $d = $_m = 0; <br>
$math = ($y2 - $y1) * 12 + $m2 - $m1; //相差总月数<br>
$y = round($math / 12); //相差年数<br>
$m = intval($math % 12); //相差月数<br>
$mm = $math; //相差总月数<br>
$d = (mktime(0, 0, 0, $m2, $d2, $y2) - mktime(0, 0, 0, $m2, $d1, $y2)) / 86400; <br>
if ($d
$m -= 1; <br>
$d += date('j', mktime(0, 0, 0, $m2, 0, $y2)); <br>
} <br>
$m
return array($y, $m, $d,$mm); <br>
}
相差天 小时 秒 计算$one = strtotime('2011-12-08 07:02:40');//开始时间 时间戳<br>
$tow = strtotime('2011-12-25 00:00:00');//结束时间 时间戳<br>
$cle = $tow - $one; //得出时间戳差值<br>
<br>
/* 这个只是提示<br>
echo floor($cle/60); //得出一共多少分钟<br>
echo floor($cle/3600); //得出一共多少小时<br>
echo floor($cle/3600/24); //得出一共多少天<br>
*/<br>
/*Rming()函数,即舍去法取整*/<br>
$d = floor($cle/3600/24);<br>
$h = floor(($cle%(3600*24))/3600); //%取余<br>
$m = floor(($cle%(3600*24))%3600/60);<br>
$s = floor(($cle%(3600*24))%60);<br>
<br>
echo "两个时间相差 $d 天 $h 小时 $m 分 $s 秒"
AD:真正免费,域名+虚机+企业邮箱=0元