PHP計算兩個日期相差的年月日時分秒
阿新 • • 發佈:2018-09-13
sta 年月日 小時 計算 時分秒 end func min con
$start_time = ‘2017-09-06 15:12:20‘; $end_time = ‘2018-09-08 10:20:45‘; get_time($start_time,$end_time); function get_time($start,$end){ $start = strtotime($start); $end = strtotime($end); if ($start > $end){ $diff_time = $start-$end; }else{ $diff_time = $end-$start; }$year_t = 3600*24*365; $day_t = 3600*24; $hours_t = 3600; $minute_t = 60; $year = floor($diff_time/$year_t); $days = floor(($diff_time-$year*$year_t)/$day_t); $hours = floor(($diff_time-($year*$year_t)-($days*$day_t))/$hours_t); $minute = floor(($diff_time-($year*$year_t)-($days*$day_t)-$hours*$hours_t)/$minute_t); $seconds = $diff_time - $minute*$minute_t-$hours*$hours_t-$days*$day_t-$year*$year_t; // $minute = floor(); echo $year.‘年‘.$days.‘天‘.$hours.‘小時‘.$minute.‘分鐘‘.$seconds.‘秒‘; }
PHP計算兩個日期相差的年月日時分秒