Pasar segundos a horas:minutos:segundos

Publicado en Programación el 5 de November de 2009 por Manel Pérez Mata
Tags: ,

Una sencilla función que dado un número de segundos, nos devuelve el tiempo en formato hh:mm:ss


protected function makeTimeFromSeconds( $total_seconds )
{
    $horas              = floor ( $total_seconds / 3600 );
    $minutes            = ( ( $total_seconds / 60 ) % 60 );
    $seconds            = ( $total_seconds % 60 );

    $time['horas']      = str_pad( $horas, 2, "0", STR_PAD_LEFT );
    $time['minutes']    = str_pad( $minutes, 2, "0", STR_PAD_LEFT );
    $time['seconds']    = str_pad( $seconds, 2, "0", STR_PAD_LEFT );

    $time               = implode( ':', $time );

    return $time;
}

Espero os sea de utilidad.

Compártelo!! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Meneame
  • BarraPunto
  • Technorati
  • Google Bookmarks
  • Facebook
  • LinkedIn
  • del.icio.us
  • Digg
  • Reddit
  • Live-MSN
  • MySpace
  • TwitThis
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply