Reputation: 7010
I´m trying to find the right pattern for a given String containing time.
Here is my String and the pattern i recently tryed:
String time = "Sun Jul 01 2012 11:25:57 GMT+0200 (CEST)";
DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE MMM dd yyyy HH:mm:ss 'GMT'ZZ '(CEST)'");
DateTime date = formatter.parseDateTime(time);
I read the documentation on which chars to use but its still not totally clear to me how to match my given timestring.
Would be awesome if one of you guys could help me out with that!
Here´s the exception i´m getting:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "Sun Jul 01 2012 11:25:57 GMT+020..."
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:866)
at Main.main(Main.java:10)
Upvotes: 0
Views: 317
Reputation: 328649
AFAIK jodatime can't parse time zone names because they are ambiguous. You can parse your string with the following pattern:
"EE MMM dd yyyy HH:mm:ss 'GMT'ZZ '(CEST)'"
That skips the time zone names, which should be fine because you also have the time zone offset (+0200).
Upvotes: 1