加起来hh:mm在php中一起写成一个字符串

时间:2013-04-20 12:12:06

标签: php function time strtotime

我试图从php中用字符串写几次总时间。

作为字符串的时间: 00.25,07.35,01.10,00.00,01.00,00.22

有了这个我应该得到10小时12分钟,但我得到11小时03分钟。

function add() 
{
    $midnight = strtotime('0.00');

    $extra = strtotime(hours($extratime));
    $taxi = strtotime(hours($taxitime));
    $flt = strtotime($flttime);
    $res = strtotime(hours($options->restime));
    $hold = strtotime(hours($holdtime));

    $totalseconds = $extra + $taxi + $flt + $res + $hold;

    return date("H.i", $midnight + $totalseconds);
}

$ holdtime,$ taxitime,$ extratime,$ options-> restime全部写成分钟,然后使用以下内容转换为小时:

function hours($min) 
{
    $mins = abs($min);
    $neg = ($min < 0) ? '-' : '' ;
    $hours = $mins / 60;
    $onlyhours = floor($hours);
    $onlymins = $mins - ($onlyhours*60);
    $time = sprintf("%s%d.%02d",$neg,$onlyhours,$onlymins);
    return $time;
}

功能小时工作正常,但功能添加不如显示后我得到11.03应该是10.12。

提前致谢,

马切伊。

1 个答案:

答案 0 :(得分:0)

请勿以小时为单位转换$ holdtime,$ taxitime,$ extratime,$ options-&gt; restime。 在几分钟内添加这些持续时间:

$total = $holdtime + $taxitime + $extratime + $options->restime;

然后以小时为单位转换$ total。