以分钟为单位的时差&;秒


Time difference in minutes & seconds?

以分钟为单位的时差&秒

问题:需要转换的差额是分钟&仅秒

    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));

答案如下:

$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在他们的答案中所建议的那样:

尝试:

功能:

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);