开发者

Pattern to parse this string to a DateTime

开发者 https://www.devze.com 2023-02-22 19:11 出处:网络
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]

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
0

精彩评论

暂无评论...
验证码 换一张
取 消