I receive a datetime with timezone as a String and want to format as a LocalDateTime to save it in Postgre as a field timestamptz but Java can't format it. I mean I want to save in the same format as i have received.
I have tried to format it with DateTimeFormatter but it throw DateTimeParseException.
This is string received: 2019-09-02T11:47:50.877+0200
and trying to format like this:
String datetimeString = "2019-09-02T11:47:50.877+0200";
String pattern = "yyyy-MM-dd\'T\'HH:mm:ss.SSS Z";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
LocalDateTime created = (LocalDateTime.from(formatter.parse(datetimeString )));
I expect this: 2019-09-02T11:47:50.877+0200
but it throw an exception.
java.time.format.DateTimeParseException: Text '2019-09-02T11:47:50.877+0200' could not be parsed at index 23