I'm trying to parse a string containing a date and time using the java.time.format.DateTimeFormatter
(my ultimate goal is to get the date from this string into a java.time.LocalDate
).
I keep getting DateTimeParseExceptions when trying to parse the date. Can someone help please?
The date is in the format "2015-07-14T11:42:12.000+01:00".
DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss.SSSZ");
LocalDateTime temp = LocalDateTime.ofInstant(Instant.from(f.parse(this.dateCreated)),
ZoneId.systemDefault());
LocalDate localDate = temp.toLocalDate();
I've tried different variations in the ofPattern, such as trying to escape the T by surrounding it with single quotes (as done above), and doing the same with the . and I've tried escaping both at the same time.
Do the colons need escaping too?
Appreciate any help with this.