1

我试图从几次写成 php 中的字符串中得到总时间。

字符串时间:00.25、07.35、01.10、00.00、01.00、00.22

这样我应该得到 10hrs12mins 但我得到 11hrs03mins。

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。

提前致谢,

马切伊。

4

1 回答 1

0

不要以小时为单位转换 $holdtime、$taxistime、$extratime、$options->restime。以分钟为单位添加这些持续时间:

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

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

于 2013-04-20T13:41:48.260 回答