给定一系列小时,分钟和秒(例如:01:30:00或00:30:00),我想将每个加起来并将总和转换为秒。
例如,如果总时间为02:30:00,则总时间应为秒。
谢谢!
答案 0 :(得分:9)
$timestr = '00:30:00';
$parts = explode(':', $timestr);
$seconds = ($parts[0] * 60 * 60) + ($parts[1] * 60) + $parts[2];
答案 1 :(得分:2)
行。
基本乘法:
<?php
$time = "01:30:00";
list ($hr, $min, $sec) = explode(':',$time);
$time = 0;
$time = (((int)$hr) * 60 * 60) + (((int)$min) * 60) + ((int)$sec);
echo $time;
?>
答案 2 :(得分:1)
尝试
<?php
$hour_one = "01:20:20";
$hour_two = "05:50:20";
$h = strtotime($hour_one);
$h2 = strtotime($hour_two);
$minute = date("i", $h2);
$second = date("s", $h2);
$hour = date("H", $h2);
echo "<br>";
$convert = strtotime("+$minute minutes", $h);
$convert = strtotime("+$second seconds", $convert);
$convert = strtotime("+$hour hours", $convert);
$new_time = date('H:i:s', $convert);
echo $new_time;
?>
答案 3 :(得分:0)
试试这个:
$string = "1:30:20";
$components = explode(":", $string);
$seconds = $components[0]*60*60 + $components[1]*60 + $components[2]