I solved the problem itself, but I wanted to know why this is happening.
The problem is this: Initially, a date and time with a time zone in String format ("dd-MM-yyyy HH:mm:ss:SSSS OOOO") is sent to the database. The application receives this date in the same format, through the mapper this date is converted to ZonnedDateTime ("dd-MM-yyyy HH:mm:ss:SSSS OOOO"), and from it back to a String in the date and time format ("dd-MM -yyyy HH:mm"). In Intellij IDEA this code works perfectly, but in Android studio an error pops up. The problem was solved by changing the format when converting time from the database to ZonnedDateTime ("dd-MM-yyyy HH:mm:ss:SSSS zzzz").
I would like to know why this is happening.
Code in Android studio:
ZonedDateTime zonedDateTime = ZonedDateTime.parse(
"22-12-2022 15:05:49:1200 GMT+10:00",
DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss:SSSS OOOO")
);
Error:
2022-12-23 12:18:13.558 24464-24464/com.example.sendmessages E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sendmessages, PID: 24464
java.time.format.DateTimeParseException: Text '22-12-2022 15:05:49:1200 GMT+10:00' could not be parsed: length=34; index=34
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:591)
at com.example.sendmessages.Mapping.MessageMapper.getEntityToDto(MessageMapper.java:18)
Same code in intellij IDEA:
ZonedDateTime zonedDateTime = ZonedDateTime.parse(
"22-12-2022 15:05:49:1200 GMT+10:00",
DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss:SSSS OOOO")
);
System.out.print(dateTimeFormatter.format(zonedDateTime));
# 22-12-2022 15:05
How the problem was solved:
ZonedDateTime zonedDateTime = ZonedDateTime.parse(
"22-12-2022 15:05:49:1200 GMT+10:00",
DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss:SSSS zzzz")
);
# 22-12-2022 15:05