Parsing dates with patterns is like parsing emails or HTML. Usually, you shouldn’t do it.
Pre Java 8, I also used those formatters but I regularly ran into bugs like yours or undiscovered edge cases.
Since Java 8, we can simply use Instant::toString and Instant::parse to convert from and to valid ISO time stamps. Replace Instant by OffsetDateTime or ZonedDateTime when you want to preserve offsets or even time zones (which is usually also
not a good idea).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Parsing dates with patterns is like parsing emails or HTML. Usually, you shouldn’t do it.
Pre Java 8, I also used those formatters but I regularly ran into bugs like yours or undiscovered edge cases.
Since Java 8, we can simply use Instant::toString and Instant::parse to convert from and to valid ISO time stamps. Replace Instant by OffsetDateTime or ZonedDateTime when you want to preserve offsets or even time zones (which is usually also
not a good idea).