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

92
Visualizações
SimpleDateFormat fails on particular date

On java 1.8 this code fails

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
dateFormat.setLenient(false);
dateFormat.setTimeZone(TimeZone.getTimeZone("America/New_York"));
dateFormat.parse("03/11/2007 02:05:01");

Interesting, that 03:05:01 parses correctly

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yes, that's because 2007-03-11T02:05:01 never occurred in the America/New_York time zone.

The spring-forward daylight saving change occurred at 2007-03-11T07:00:00Z, so anyone watching a time-zone-aware clock would have seen:

  • 01:59:58
  • 01:59:59
  • 03:00:00
  • 03:00:01

You've told the SimpleDateFormat to handle the input strictly, then given it a date/time that didn't exist, so it's reasonable for it to fail.

Importantly, regardless of how you want to handle this, I would strongly encourage you to move off the legacy Date/Calendar/DateFormat types, and use java.time instead.

over 4 years ago · Santiago Trujillo 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