我想在 PHP 中将时间字符串(例如 2:12:0)转换为以小时为单位的十进制格式(例如 2:12:0 将是 2.2 小时).
I would like to convert time strings (Such as 2:12:0) to decimal format in hours (ex 2:12:0 would be 2.2 hours) in PHP.
一个相当愚蠢的转换,使用冒号爆炸:
A fairly dumb conversion from the top of my head, using explode by colon:
<?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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!