如何在PHP中计算整数和小数值的小时和分钟


How to compute Hours and Minutes in PHP with value of whole number and decimal

如果我有

例如 3.56 至 2.43 小时/分钟

我已经手动计算了这个例子,并且

如果十进制数大于 60 分钟,我想计算这个。 将添加到小时,如果<分钟将保持为分钟。>

星期五中午后代码 :-)

function sumTime($a,$b)
{
    $ah=explode('.',$a);
    $bh=explode('.',$b);
    $hours=$ah[0]+$bh[0];
    $minutes=$ah[1]+$bh[1];
    if($minutes <60){
    $done= $hours.'.'.$minutes;
    }else{
    $x= $minutes%60;
    $done=($hours+1) .'.'.$x;
    }
    return $done;
}
echo sumTime('3.56','2.43');