Skip to content
Advertisement

Tag: java.time.instant

Parse string with offset to Instant Java 11

I am trying to parse the following string 2021-10-15T08:39:05+02:00 into an Instant this works seamlessly using Java 15 but throws an error for Java 11. java.time.format.DateTimeParseException: Text ‘2021-10-19T11:06:35+02:00’ could not be parsed at index 19 Why is that the case? Edit: Java 15 Answer Instant.parse says: The string … is parsed using DateTimeFormatter.ISO_INSTANT. So, read the docs for DateTimeFormatter.ISO_INSTANT: Java

Java Instant.parse cannot validate date

I have an instant field and trying to validate the values in this field using the following approach: Instant.parse(“2021-09-29 09:35:07.531”) However, it throws the error: java.time.format.DateTimeParseException: Text ‘2021-09-29 09:35:07.531’ could not be parsed at index 10. So, how can I test if the given Instant date in String format is a valid Instant date? I am implementing an Import feature

Converting string to Instant

I am trying to covert datetime in string to instant using java 8 or utils package. For eg. to reqString is in America/Toronto timezone. This is what I tried The above code results in “2018-05-12T23:30:00Z”. Any help is appreciated. Answer tl;dr Fix your formatting pattern for unpadded month & day. Use only java.time classes, never the legacy classes. Contrived example:

Advertisement