What's actually changed in Android 12 that suddenly code is getting
failed?
Earlier, the short name for September in the Locale.UK
was Sep but it got changed to Sept starting with Java 16. Check this related thread.
There is no change in other short names in the Locale.UK
and therefore it worked for Wed Mar 23 14:28:32 +0000 2016 for example.
Modern Date-Time API
For the sake of completeness, I would like to discuss a bit about the modern date-time API. Probably you must have already seen the following note on the Home Page of the Joda-Time API:
Note that from Java SE 8 onwards, users are asked to migrate to java.time (JSR-310) - a core part of the JDK which replaces this
project.
Demo using the modern date-time API:
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
public class Main {
public static void main(String[] args) {
String strDateTime = "Sun Sep 04 17:29:52 +0000 2022";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss Z yyyy", Locale.ROOT);
OffsetDateTime zdt = OffsetDateTime.parse(strDateTime, formatter);
System.out.println(zdt);
}
}
Output:
2022-09-04T17:29:52Z
Notice that I have use Locale.ROOT
in the demo. If you use Locale.UK
, it will throw the same error that you have got. However, if you change Sep to Sept and use Locale.UK
, it will work.
Learn more about the modern Date-Time API from Trail: Date Time.