This part of code make a sort of conversion from an input like "January 1, 2020" to "01/01". The whole code works perfectly on devices with Android up to Pie and in AVD with devices with Q and R too. When I try to run it on phisycal Android devices with Android Q it doesn't run (I tried with 2 different devices a Mi Note 10 and a OnePlus 6T). I did a check on the debugger and I found this error as soon as it go in the IF loop (I think in the instruction: @SuppressLint("SimpleDateFormat") SimpleDateFormat dt = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy");"
W/System.err: java.text.ParseException: Unparseable date: "Thu Nov 05 00:00:00 GMT+01:00 2020"
String[] mese = new String[] {"January","February","March","April","May","June","July","August","September","October","November","December"};
int a= 0 ;
while (a < 12){
if(dato.contains(mese[a])){
System.out.println("Test 3");
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
Date date = format.parse(dato);
@SuppressLint("SimpleDateFormat") SimpleDateFormat dt = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy");
Date date2 = dt.parse(String.valueOf(date));
@SuppressLint("SimpleDateFormat") SimpleDateFormat dt1 = new SimpleDateFormat("dd/MM");
assert date2 != null;
dato = dato.replaceAll(dato,dt1.format(date2));
}
a++;
}
my pattern is wrong? I tried EEE MMM dd HH:mm:ss zzz yyyy and EEE MMM dd HH:mm:ss zzzz yyyy but same results
SimpleDateFormatand friends. See if you either can use desugaring or add ThreeTenABP to your Android project, in order to use java.time, the modern Java date and time API. It is so much nicer to work with.