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 from Instant to XMLGregorianCalendar and vice-versa without losing precision

Using, java.time.Instant and javax.xml.datatype.XMLGregorianCalendar, I’m trying to convert from one to the other without losing precision. Why is this test not passing and how to fix it? Answer Why is this test not passing? Your XMLGregorianCalendar has got the full precision of your Instant. It’s your conversion back to Instant that is lossy. You are converting to GregorianCalendar through the

Converting string to ‘Instant’

I am trying to convert datetime in a string to an Instant instance using Java 8 or a utilities package. For example, to reqString is in the America/Toronto time zone. This is what I tried The above code results in “2018-05-12T23:30:00Z”. How can I do it? Answer tl;dr Fix your formatting pattern for unpadded month and day. Use only java.time

Convert java.time.Instant to java.sql.Timestamp without Zone offset

In the application I am developing, I need to convert java.time.Instant object to java.sql.Timestamp. When I create Instant object like: I receive something like 2017-03-13T14:28:59.970Z. And when I try to create Timestamp object like this: I receive something like 2017-03-13T16:28:59.970Z. The same result but with an additional 2 hour delay. Can someone explain why this is happening and provide me

Advertisement