分钟和时差秒?

时间:2013-12-13 09:07:07

标签: php datetime logic

分钟与时差秒

问题:需要转换差异是分钟&只有几秒钟

    expected output : 130:04 (i:s)

    example : 

    $fromdate = "12/12/2013 21:00:02"

    $endData = "12/12/2013 23:10:06"

tried : date('i:s', strtotime( $endData) - strtotime( $fromdate));

1 个答案:

答案 0 :(得分:1)

以下是答案:

$to_time = strtotime("2008-12-13 10:42:00");
$from_time = strtotime("2008-12-13 10:21:00");
$totalMinutes = round(abs($to_time - $from_time) / 60,2);
$hours = intval($totalMinutes/60);
$minutes = $totalMinutes - ($hours * 60);

<强>编辑。

或正如Teena Thmoas在their answer中所建议的那样:

  

尝试:

     

功能:

function date_difference ($date1timestamp, $date2timestamp) {
$all = round(($date1timestamp - $date2timestamp) / 60);
$d = floor ($all / 1440);
$h = floor (($all - $d * 1440) / 60);
$m = $all - ($d * 1440) - ($h * 60);
//Since you need just hours and mins
return array('hours'=>$h, 'mins'=>$m);
}
     

调用该函数:

$result = date_difference($date1timestamp, $date2timestamp);