I don’t understand why the following lines of code are not working with Joda Time:
DateTime now = new DateTime();
DateTimeFormatter dateTimeFormatter = DateTimeFormat.
forPattern("yyyyMMddhhmmss Z");
System.out.println(dateTimeFormatter.print(now));
DateTime d = x.parseDateTime("200906031633 -0300");
I get this error:
java.lang.IllegalArgumentException: Invalid format: “200006031633 -0300″ is malformed at ” -0300″ at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:683)
What is strange for me is that the System.out.prinln(dateTimeFormatter.print(now)); it’s fine and prints according to the pattern:
20110131101805 +0100
What is the problem? From what I read on Joda Time’s pattern syntax, the pattern seems correct.
Thank you!
First of all your pattern should use “HH” not “hh” if you expect it to parse that value. Secondly, you’ll need to include seconds in the value as well.
E.g.