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

296
Vistas
how to get a duration in human format (1 hours, 4 minutes)

I'm using 'moment' library. I have a duration in minutes, and I want it to be humanized.

For example:

const totalMinutes = 124;
console.log(moment.duration(totalMinutes, 'minutes').humanize()); // prints 2 hours

but that's not what I want, I want it to be:

124 => 2 hours, 4 minutes

34 => 34 minutes // no hours

725 => 12 hours, 5 minutes

I don't care about days or seconds.

I know that I can somehow extract the hours and minutes and join them to make the final string, but I feel there is a shorter way at least using the library itself. Not to mention that I want the text to be localized in other languages, which moment library itself support.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Unfortunately, it seems that Moment JS library doesn't have this out of the box, and I had to use another library.

Here is the solution:

import humanizeDuration from "humanize-duration";

console.log(humanizeDuration(658 * 60 * 1000, { language: 'en'})); 
// prints 10 hours, 58 minutes
console.log(humanizeDuration(55 * 60 * 1000, { language: 'en'})); 
// prints 55 minutes

which is exactly what I want.

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