fork(3) download
  1. <?php
  2. function getFullHour($input) {
  3. $seconds = intval($input); //Converte para inteiro
  4.  
  5. $negative = $seconds < 0; //Verifica se é um valor negativo
  6.  
  7. if ($negative) {
  8. $seconds = -$seconds; //Converte o negativo para positivo para poder fazer os calculos
  9. }
  10.  
  11. $hours = floor($seconds / 3600);
  12. $mins = floor(($seconds - ($hours * 3600)) / 60);
  13. $secs = floor($seconds % 60);
  14.  
  15. $sign = $negative ? '-' : ''; //Adiciona o sinal de negativo se necessário
  16.  
  17. return $sign . sprintf('%02d:%02d:%02d', $hours, $mins, $secs);
  18. }
  19.  
  20. echo getFullHour(685), PHP_EOL; //00:11:25
  21.  
  22. echo getFullHour(140801), PHP_EOL; //39:06:41
  23. echo getFullHour(100800), PHP_EOL; //28:00:00
  24.  
  25. echo getFullHour(-140801), PHP_EOL; //-39:06:41
  26. echo getFullHour(-100800), PHP_EOL; //-28:00:00
Success #stdin #stdout 0.02s 23568KB
stdin
Standard input is empty
stdout
00:11:25
39:06:41
28:00:00
-39:06:41
-28:00:00