Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. function explode_time($time) { //explode time and convert into seconds
  2. $time = explode(':', $time);
  3. $time = $time[0] * 3600 + $time[1] * 60 + $time[2];
  4. return $time;
  5. }
  6.  
  7. function second_to_hhmm($time) { //convert seconds to hh:mm
  8. $hour = floor($time / 3600);
  9. $minute = strval(floor(($time % 3600) / 60));
  10. $second = $time%$minute;
  11.  
  12. if ($minute == 0) {
  13. $minute = "00";
  14. } else {
  15. $minute = $minute;
  16. }
  17. $time = $hour . ":" . $minute .":". $second;
  18. return $time;
  19. }
  20.  
  21. $time = 0;
  22. $time_arr = array("23:59:10","01:01:10","2:50:00");
  23. foreach ($time_arr as $time_val) {
  24. $time +=explode_time($time_val); // this fucntion will convert all hh:mm:ss to seconds
  25. }
  26.  
  27. echo $time;
  28. echo '<pre>';
  29. echo second_to_hhmm($time);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement