<分区>
我想在 PHP 中将时间字符串(例如 2:12:0)转换为以小时为单位的十进制格式(例如 2:12:0 将是 2.2 小时)。
<分区>
我想在 PHP 中将时间字符串(例如 2:12:0)转换为以小时为单位的十进制格式(例如 2:12:0 将是 2.2 小时)。
最佳答案
从我的头顶开始的一个相当愚蠢的转换,使用冒号分解:
<?php
$hms = "2:12:0";
$decimalHours = decimalHours($hms);
function decimalHours($time)
{
$hms = explode(":", $time);
return ($hms[0] + ($hms[1]/60) + ($hms[2]/3600));
}
echo $decimalHours;
?>
关于php - 将时间字符串转换为小数小时 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13595935/