php計算兩個時間差
阿新 • • 發佈:2018-07-06
min turn rto 計算 str rtti @param gin val /**
* 計算兩個時間差
* @param [type] $start [description]
* @param [type] $end [description]
* @return [type] [description]
*/
function cdate($start,$end)
{
$begin_time = strtotime($start);
$end_time = strtotime($end);
if($begin_time < $end_time){
$starttime = $begin_time;
$endtime = $end_time;
}else{
$starttime = $end_time;
$endtime = $begin_time;
}
//計算天數
$timediff = $endtime-$starttime;
$days = intval($timediff/86400);
//計算小時數
$remain = $timediff%86400;
$hours = intval($remain/3600);
//計算分鐘數
$remain = $remain%3600;
$mins = intval($remain/60);
//計算秒數
$secs = $remain%60;
$res = array("day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs);
$str=$days."天".$hours."時".$mins."分".$secs."秒";
return $str;
}
php計算兩個時間差