this Code is throwing the "invalid format" or "malformed" Exception:
Code:
strDate = "21/10/2015 12:00:00 AM";
format = "dd/MM/yyyy hh:mm:ss a";
DateTime.parse(strDate, DateTimeFormat.forPattern(format)).toDate();
Exception:
java.lang.IllegalArgumentException: Invalid format: "21/10/2015 12:00:00 AM"
is malformed at "AM"
What's wrong?
I'm ussing joda-time:2.8.1
(I already searched and i think this is the correct pattern for that strDate)
The text of the AM/PM marker may be different to that of your default locale. You could do
Date date =
DateTime.parse(strDate, DateTimeFormat.forPattern(format).withLocale(Locale.US)).toDate();
Depends on the locale, you may specify the locale and timezone :
these should work for you:
DateTime.parse(strDate, DateTimeFormat.forPattern(format).withLocale(Locale.US)).withZone(DateTimeZone.UTC).toDate();
or
DateTime.parse(strDate, DateTimeFormat.forPattern(format).withLocale(Locale.US)).toDate();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With