Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

724
Visualizações
moment.js How to get the exact hour from seconds?

I have a timer in my project, I have time format in seconds 90000 I want to transform seconds in hours and minutes (HH:mm) using moment.js, I wonder how I can get the exact time, if time is less than 86399 moment works as expected, but my aim is to get such a result 25:00, is this possible with moment?

const secs = 90000;
const formatted = moment.utc(secs*1000).format('HH:mm');

document.write(formatted);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Its not possible with moment since moment works with 12/24 hours formats. However you can use basic Math

      const formatMMSS = (timeInSeconds) => {
        const time = (timeInSeconds/60/60).toFixed(2)
        const hh = time.split('.')[0]
        let mm = (parseFloat('0.'+time.split('.')[1])*60).toString().split('.')[0]
        if(mm.length == 1){
            mm = '0'+mm
           }
          return hh+':'+ mm;
        }
     console.log(formatMMSS(90000));

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this

var seconds = 90000;
// multiply by 1000 because Date() requires miliseconds
var date = new Date(seconds * 1000);
var hh = date.getUTCHours();
var mm = date.getUTCMinutes();
var ss = date.getSeconds();
// If you were building a timestamp instead of a duration, you would uncomment the following line to get 12-hour (not 24) time
// if (hh > 12) {hh = hh % 12;}
// These lines ensure you have two-digits
if (hh < 10) {hh = "0"+hh;}
if (mm < 10) {mm = "0"+mm;}
if (ss < 10) {ss = "0"+ss;}
// This formats your string to HH:MM:SS
var t = hh+":"+mm+":"+ss;
document.write(t);
// result 1:00:00
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda