I've been trying to parse a simple date using JodaTime since yesterday and so far I keep on failing.....
Here's a (random) date I'm trying to parse: 2017-Sept-14 (Even with S in upper case doesn't change anything...)
Here's my code
DateTimeFormatter dateTimeFormat = DateTimeFormat.forPattern("yyyy-MM-dd");
// The variable 'parsed' is a dynamic string. For now I set it to 2017-sept-14
DateTime dateTime = dateTimeFormat.parseDateTime(parsed);
Log.d(TAG, "Parsed date = "+ dateTime.toString());
And here's the exception I have:
java.lang.IllegalArgumentException: Invalid format: "2017-sept-14" is malformed at "sept-14" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
What am I missing here ??
UPDATE: Actually what I get from my textfield is in the form above i.e date-month-day (the month is 3 or 4 characters long depending on the month....) So what I want to get as output when I have 2017-sept-14 is simply 2017-09-14
So I don't know know if it's the right way but this worked for me (I ended up using SimpleDateFormat...) :