I am making an app that use an API that give data with timestamps. The timestamp looks like:
Jul 20, 2018
I want to convert the string to a date. I try this code to parse the string to a Date.
DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy", Locale.US);
Date date = dateFormat.parse("Jul 20, 2018");
but I even can't compile my code. Every time I try to parse a string with dateformat.parse() I got the following compile error:
java.text.ParseException
This even shows up when hovering above the the .parse() in code I browsed the whole day and tried a couple of different thing, but every time I use .parse() I got this error. I really dot know what to do any more.
I don't have the permission to post images yet, but you can watch the screenshot over here:https://i.stack.imgur.com/Jr7Ep.jpg
I am using Java 8 (with support for lambda notation). I am using androidx.legacy:legacy-support library, minimum API 19 and targetting API 28. (So the solution for this problem should support older devices as well)
Other things I tried but failed:
Android, How can I Convert String to Date?
Cant convert String to date in android
How to convert "2017-04-26T20:55:00.000Z" string to a Date in java android studio