原出处:http://www.cnblogs.com/wang1204/p/5670920.html
//功能:计算两个时间戳之间相差的日时分秒
//$begin_time 开始时间戳
//$end_time 结束时间戳
<span style="font-size:14px;"><span style="white-space:pre"> </span>function timediff($begin_time,$end_time)
{
<span style="white-space:pre"> </span> if($begin_time < $end_time){
<span style="white-space:pre"> </span> $starttime = $begin_time;
<span style="white-space:pre"> </span> $endtime = $end_time;
}else{
<span style="white-space:pre"> </span> $starttime = $end_time;
<span style="white-space:pre"> </span> $endtime = $begin_time;
}
<span style="white-space:pre"> </span> //计算天数
<span style="white-space:pre"> </span> $timediff = $endtime-$starttime;
<span style="white-space:pre"> </span> $days = intval($timediff/86400);
<span style="white-space:pre"> </span> //计算小时数
<span style="white-space:pre"> </span> $remain = $timediff%86400;
<span style="white-space:pre"> </span> $hours = intval($remain/3600);
<span style="white-space:pre"> </span> //计算分钟数
<span style="white-space:pre"> </span> $remain = $remain%3600;
<span style="white-space:pre"> </span> $mins = intval($remain/60);
<span style="white-space:pre"> </span> //计算秒数
<span style="white-space:pre"> </span> $secs = $remain%60;
<span style="white-space:pre"> </span> $res = array("day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs);
<span style="white-space:pre"> </span> return $res;
}
<span style="white-space:pre"> </span>print_r(timediff(strtotime(2015-03-20 16:20:30'),strtotime('2015-05-25 11:10:10')));</span>