I'm trying to receive a string to a date. Here's an example of the string:
val date = "10/10/2016 12:00:00 AM" //format month/day/year
Now, I'd like to convert this string into a date. To do that, I'm trying to run the following:
val formatter = SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa")
var date = formatter.parse(date)
Whenever this code is running on devices running android 8, everything works out great. However, if I try to run in older devices (ex.: phones using Android 6), I end up with a ParseException:
Unparseable date: "10/10/2016 12:00:00 AM" (at offset 20)
I've noticed that removing the AM/PM characters (aa)
from the string solves the parsing exception. Can someone please tell me what's going on here?
thanks
Regards, Luis
PS: the code runs without any problem in the emulator, but not in real devices