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

221
Visualizações
How to format JavaScript Date object to not let hours overflow?

Let us consider following example

const date = new Date(0);
date.setSeconds(60*60*24-1);
console.log(date.toISOString().substr(11, 8));

outputs

23:59:59

I am searching for elegant way to have

const date = new Date(0);
date.setSeconds(60*60*24+1);
console.log(date.toISOString().substr(11, 8));

output

24:00:01

instead of

00:00:01

by elegant I mean without implementing my own Date object... Maybe it would be possible to set a custom length of the day? Increase from 24h to 99h?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can set the hour cycle in the hour cycle option (hr) and the language parameter available in the Intl.DateTimeFormat constructor and toLocaleTimeString, e.g.

console.log(
  new Date(2020,7,1,0,5).toLocaleTimeString('en-CA-u-hc-h24')
);

Whether the hour cycle setting "works" or not seems to depend on the language chosen and how it's set, so maybe not that reliable. Test thoroughly in different implementations.

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