fork download
  1. <?php
  2.  
  3. function obterSegundos($tempo){
  4. $tempos = explode(":", $tempo);
  5. $horasmins = (int)$tempos[0] * 3600 + (int)$tempos[1] * 60;
  6. return count($tempos) === 2 ? $horasmins : $horasmins + (int)$tempos[2];
  7. }
  8.  
  9. function formatarSegundos($total){
  10. $horas = floor($total / 3600);
  11. $minutos = floor(($total - $horas * 3600) / 60);
  12. $segundos = $total % 60;
  13. return $segundos ?
  14. sprintf('%02d:%02d:%02d', $horas, $minutos, $segundos):
  15. sprintf('%02d:%02d', $horas, $minutos);
  16. }
  17.  
  18. $t1 = "18:00";
  19. $t2 = "08:30:09";
  20. $total = obterSegundos($t1) + obterSegundos($t2);
  21. $t3 = formatarSegundos($total); //26:30:09
  22.  
  23. var_dump($t3);
Success #stdin #stdout 0.02s 23344KB
stdin
Standard input is empty
stdout
string(8) "26:30:09"