Reputation: 4573
Joda time throws exception as:
java.lang.IllegalArgumentException: Invalid format: "23-Apr-2020 10:35:06 AM UTC" is malformed at "-Apr-2020 10:35:06 AM UTC" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:873) at org.joda.time.DateTime.parse(DateTime.java:144) at org.joda.time.DateTime.parse(DateTime.java:133)
The line of code causing this exception is:
public static DateTimeFormatter LicenseFormat = DateTimeFormat.forPattern("dd-MMM-yyyy hh:mm:ss a z").withZone(DateTimeZone.UTC).withLocale(Locale.ENGLISH);
DateTime webDate = DateTime.parse(DateTime.now().toString(LicenseFormat));
I am not able to trace down the issue, the date "23-Apr-2020 10:35:06 AM UTC" is in correct format of "dd-MMM-yyyy hh:mm:ss a z" then why it's throwing exception.
Upvotes: 0
Views: 3136
Reputation: 4573
Oh very minor issue, I should pass second argument to method parse()
of type DateTimeFormatter
.
As:
DateTime webDate = DateTime.parse(DateTime.now().toString(LicenseFormat), LicenseFormat);
Upvotes: 1