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

356
Vistas
Date.toLocaleString('en-US', {hour12: false}) is providing midnight as 24

The code

const d = new Date('2021-08-04T18:33:43.0000000Z')
  .toLocaleString('en-US', {hour12: false, timeZone: "Asia/Kolkata"}) 
console.log(d)

is providing result as "8/5/2021, 24:03:43".
Here '24' hr should be shown as '00' hr. Is this a toLocaleString function issue?

I need to use as above syntax because, date format should be browser language date format and time should be 24 hr format.

For other language its works fine, for example GB

const d = new Date('2021-08-04T18:33:43.0000000Z')
  .toLocaleString('en-GB', {hour12: false, timeZone: "Asia/Kolkata"}) 
console.log(d)

will provide result as "05/08/2021, 00:03:43".

So can someone help me how to get the correct 24 hour format time by using toLocaleString function?

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

0

Seems to be a bug in INTL ECMA specifications, which should be fixed in ECMA2021.

It may be a Chromium only issue

In the mean time you can add hourCycle: 'h23' to your parameters to force the 00 since h24 is default for SOME locales when hour12: false is specified

https://github.com/moment/luxon/issues/726

The root cause of this issue comes from this change in Chromium. It introduces support for the hourCycle option in Intl.DateTimeFormat.
The four supported values are "h11", "h12", "h23", or "h24" (MDN) and the difference between h23 and h24 is precisely if midnight should be displayed as 00 (h23) or 24 (h24)

What are the differences between the hourCycle options in Date.prototype.toLocaleTimeString()

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to use hourCycle: 'h23' option to force 0-23 hours format.

> new Date('2021-08-04T18:33:43.0Z').toLocaleString('en-US', { hourCycle: 'h23'})
"8/5/2021, 00:33:43"
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