I want to parse a DateTime using the joda library (in scala, but should be the same with java).
The source looks like
val dateParser = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss z")
val date = dateParser.parseDateTime("2012-08-28 15:35:00 CEST")
In Java this would look like
DateTimeFormatter dateParser = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss z");
DateTime date = dateParser.parseDateTime("2012-08-28 15:35:00 CEST");
Unfortunately this doesn't work but throws an exception:
java.lang.IllegalArgumentException: Invalid format: "2012-08-28 15:35:00 CEST" is malformed at "CEST"
Why doesn't this work? Of course I could ignore the "CEST" part and just parse the rest, but in the input "CEST" can be replaced by "CET" sometimes, so I don't want to ignore it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…