Ver Mensaje Individual
  #17 (permalink)  
Antiguo 05/06/2009, 22:16
Avatar de Ronruby
Ronruby
 
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 8 meses
Puntos: 416
Respuesta: Cantidad de Tiempo

Código php:
Ver original
  1. function sec2hms ($sec, $padHours = false)
  2.   {
  3.  
  4.     // holds formatted string
  5.     $hms = "";
  6.    
  7.     // there are 3600 seconds in an hour, so if we
  8.     // divide total seconds by 3600 and throw away
  9.     // the remainder, we've got the number of hours
  10.     $hours = intval(intval($sec) / 3600);
  11.  
  12.     // add to $hms, with a leading 0 if asked for
  13.     $hms .= ($padHours)
  14.           ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
  15.           : $hours. ':';
  16.      
  17.     // dividing the total seconds by 60 will give us
  18.     // the number of minutes, but we're interested in
  19.     // minutes past the hour: to get that, we need to
  20.     // divide by 60 again and keep the remainder
  21.     $minutes = intval(($sec / 60) % 60);
  22.  
  23.     // then add to $hms (with a leading 0 if needed)
  24.     $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
  25.  
  26.     // seconds are simple - just divide the total
  27.     // seconds by 60 and keep the remainder
  28.     $seconds = intval($sec % 60);
  29.  
  30.     // add to $hms, again with a leading 0 if needed
  31.     $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
  32.  
  33.     // done!
  34.     return $hms;
  35.    
  36.   }

Reemplaza & #37; por %

http://www.laughing-buddha.net/jon/php/sec2hms/