Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

358
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda