Pattern to parse this string to a DateTime
Hey everyone I am trying to parse out a DateTime
from a string that looks like "20110406080000.000[-4:EDT]"
and am running into problems with the [-4:EDT]
DateTimeFormat.forPattern("yyyyMMddHHmmss.SSS[ZZ]").parseDateTime("20110406080000.000[-4:EDT]")
results in the following error
java.lang.IllegalArgumentException: Invalid format: "20110406080000.000[-4:EDT]" is malformed at "-4:EDT]"
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:673)
at .<init>(<console>:8)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.refle开发者_开发问答ct.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$17.apply(Interpreter.scala:988)
at scala.tools.nsc.Interpreter$...
Any suggestions would be greatly appreciated.
You need to either
- strip the suffix off before parsing
- write your own DateTimeParser for the end part, using DateTimeFormatterBuilder to combine your parser with a standard parser for the first part
精彩评论