Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 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; ?>