Convert seconds to hours in Extjs

Asked

Viewed 1,948 times

0

I’m looking to convert seconds into hours in Extjs and would like to know if there is a function similar to gmdate("H:i:s", $total) in PHP.

  • What format do you want? There is an answer to that question: [1]: http://stackoverflow.com/questions/2066447/how-to-display-time-and-date-in-extjs

2 answers

1

You can do a function in javascript. Something like:

function segundosParaHora(seg) {
        var horas = Math.floor(seg/(60*60));

        var resto = seg % (60*60);
        var minutos = Math.floor(seg/60);

        resto %= 60;
        segundos = Math.ceil(resto);

        var hora = {
            "H": horas,
            "i": minutos,
            "s": segundos
        };
        return hora;
}

I used 60*60 for readability (60s in 1min and 60min in 1 hour), but you can put the 3600 without problem.

1

I had trouble finding a JS function that actually works.

I’ll leave here the one who attended to my needs:

function segParaHora(time, with_seg = true){
    
  var hours = Math.floor( time / 3600 );
  var minutes = Math.floor( (time % 3600) / 60 );
  var seconds = time % 60;
    
  minutes = minutes < 10 ? '0' + minutes : minutes;      
  seconds = seconds < 10 ? '0' + seconds : seconds;
  hours = hours < 10 ? '0' + hours : hours;
    
  if(with_seg){
     return  hours + ":" + minutes + ":" + seconds;
  }
    
  return  hours + ":" + minutes;
}
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.