Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function explode_time($time) { //explode time and convert into seconds
- $time = explode(':', $time);
- $time = $time[0] * 3600 + $time[1] * 60 + $time[2];
- return $time;
- }
- function second_to_hhmm($time) { //convert seconds to hh:mm
- $hour = floor($time / 3600);
- $minute = strval(floor(($time % 3600) / 60));
- $second = $time%$minute;
- if ($minute == 0) {
- $minute = "00";
- } else {
- $minute = $minute;
- }
- $time = $hour . ":" . $minute .":". $second;
- return $time;
- }
- $time = 0;
- $time_arr = array("23:59:10","01:01:10","2:50:00");
- foreach ($time_arr as $time_val) {
- $time +=explode_time($time_val); // this fucntion will convert all hh:mm:ss to seconds
- }
- echo $time;
- echo '<pre>';
- echo second_to_hhmm($time);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement