I'm trying to get a UTC time from a Javascript front end to a Java backend. I wanted to accomplish this by using Date.toISOString() and sending that object to the Java backend. However, an issue I noticed is that toISOString() returns the timestamp in YYYY-MM-DDTHH:mm:ss.sssZ format, and this format does not match any of the Java 8 pre-defined LocalDateTime formatters.
My question is, is there a best practice to do what I'm trying to do? I'm aware I can write a custom Java formatter to match the Javascript output. However, I wondered if there was a standard way to accomplish this as it seems like a very common case.
LocalDateTimein which time zone? If server time zone, useLocalDateTime.ofInstant(Instant.parse(dateString), ZoneId.systemDefault())--- Are you sure you want a local date/time?LocalDateTimeis the wrong class to use on the Java side. Your ISO string defines a point in time.LocalDateTimecannot represent that. UseInstantorZonedDateTime.