Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

287
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!