I have a SpringBoot 2.6.14 web-app with JPA 2.2 and Hibernate 5.
Now I have a String with this format
"2024-03-04T14:10:37.000Z"
And, following some instruction (googling around) I write the following String to LocalData converter:
default LocalDate stringToDate(String data) {
if (data == null || data.isEmpty()) return null;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
formatter = formatter.withLocale(Locale.getDefault());
return LocalDate.parse(data, formatter);
}
The parsing works but the result is 2024-03-04, the hour, minutes and seconds are truncated. What's wrong?
LocalDate, as the name suggests, does not include a time. Consider usingLocalDateTimeinstead.