Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

725
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda