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

312
Vistas
Intl.DateTimeFormat inconsistent between Chrome/Node and Firefox

Given the following code:

const foo = new Intl.DateTimeFormat('en-GB', {
  hourCycle: 'h12',
  timeStyle: 'short',
  dateStyle: 'short',
}).format(1650442310319);

The output in Chrome/Node is 20/04/2022, 09:11 am whilst the output in Firefox is 20/04/2022, 9:11 am. Notice the leading 0 on the hour being inconsistent.

One way to fix this for this en-GB locale is:

const bar = new Intl.DateTimeFormat('en-GB', {
  day: '2-digit',
  month: '2-digit',
  year: 'numeric',
  hourCycle: 'h12',
  hour: 'numeric',
  minute: '2-digit',
}).format(1650442310319);

Now the output in both browsers is 20/04/2022, 9:11 am. However, this breaks formatting by locale. For example if I switch to en-US, the string we'd want is 4/20/2022, 9:11 am but we actually get 04/20/2022, 9:11 am because we specified 2 digits for the day and month.

It looks like the ideal solution would be to combine the approaches, such as:

const foo = new Intl.DateTimeFormat('en-GB', {
  hourCycle: 'h12',
  hour: 'numeric',
  minute: '2-digit',
  dateStyle: 'short',
}).format(1650442310319);

But alas this is not possible. As the MDN docs say:

Note: dateStyle can be used with timeStyle, but not with other options (e.g. weekday, hour, month, etc.).

So is there any way to use this native datetime formatter consistently, without sacrificing the benefits of formatting by locale, which is one of the primary purposes of it?

about 4 years ago · Juan Pablo Isaza
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