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

275
Views
get plural value for time units (days, hours, minutes) using Intl API

I'm trying to localize time units and I'm able to do so for singular (hour, day, minute) but I'm unable to find any way to figure out the plural equivalent (hours, days, minutes). Is it not supported or am I missing something obvious. I looked at Intl.PluralRules thinking that'd be helpful but with no luck. Would appreciate any tips.

let locale = "en-US";
let days = new Intl.DisplayNames(locale, { type: 'dateTimeField', style: 'long' }).of('day');
let hours = new Intl.DisplayNames(locale, { type: 'dateTimeField', style: 'long' }).of('hour');
console.log(days,hours);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should take a look at Intl.RelativeTimeFormat.prototype.formatToParts(). This method returns three parts of a RelativeTimeFormat, last one of which is an object with time unit.

const rtf1 = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
const parts = rtf1.formatToParts(10, 'seconds');

console.log(parts[2].value);
// expected output: " seconds"
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!