I'm getting two different date outputs on different versions of Android
ZonedDateTime.parse("Mon, 31 Jul 2023 18:57:55 +0000", DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneId.systemDefault())).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
On Android 13 the output is:
2023-07-31 14:57:55
on Android 9 and 11 the output is:
2023-07-31 18:57:55
If I log ZoneId.systemDefault() all versions return: America/New_York
Android 13 has the correct date. However if I used a LocalDateTime instead of ZonedDateTime then the wrong date is also outputted on Android 13.
Same result happens if I use
ZonedDateTime.parse("Mon, 31 Jul 2023 18:57:55 +0000", DateTimeFormatter.ofPattern("EEE, d MMM yyyy HH:mm:ss z").withZone(ZoneId.systemDefault())).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
Update: I tried changing the time zone to "America/Los_Angeles" and this is the result for a different date:
ZonedDateTime dateTime = ZonedDateTime.parse("Tue, 01 Aug 2023 10:00:00 -0000", DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneId.systemDefault())).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
Android 13: 2023-08-01 03:00:00
Android 11: 2023-08-01 10:00:00
I should add I am converting all of my java.util.Date code to java.time and this didn't happen with the old code.