SimpleDateFormat string parsing issue in a Specific Android Device

192 Views Asked by At

I have a released android app and a strange issue has cropped up with a specific device. On analysis of Crashlytics data, I found that the app is crashing for this particular user (and device) because of the following reason:

val time1 = SimpleDateFormat("MMM dd yyyy HH:mm:ss",Locale.getDefault()).parse(dateString)

where dateString is "Sep 6 2023 14:00:00"

The exact error reported issue is

Caused by java.text.ParseException Unparseable date: "Sep 6 2023 14:00:00"

I have not faced this issue before in other devices. The specifics of the device are:

Device Brand:Xiaomi Model:Redmi Note 10 Pro Orientation:Portrait RAM free: 1.88 GB Disk free: 2.48 GB Operating System Version:Android 13 Orientation:Portrait Rooted:No Crash Date:Sep 5, 2023, 4:19:40 PM App version:6.1.2 (54)

Additional input:

It also fails with

deteString: "Sep 15 2023 24:00:00"

So the problem is not with d or dd

1

There are 1 best solutions below

5
Sohaib Ahmed On

Your date is of single character e.g. '6' in "Sep 6 2023 14:00:00"

Try format "MMM d yyyy HH:mm:ss" as follow:

val pattern = SimpleDateFormat("MMM d yyyy HH:mm:ss", Locale.getDefault())
val time1 = pattern.parse(dateString)

or update your date generation to '06' for single characters