Joda Time 时区模式出现无效格式错误
我不明白为什么以下代码行不适用于 Joda Time:
DateTime now = new DateTime();
DateTimeFormatter dateTimeFormatter = DateTimeFormat.
forPattern("yyyyMMddhhmmss Z");
System.out.println(dateTimeFormatter.print(now));
DateTime d = x.parseDateTime("200906031633 -0300");
我收到此错误:
java.lang.IllegalArgumentException:格式无效:“200006031633 -0300”在 org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:683) 的“-0300”处格式错误
对我来说奇怪的是 System.out.prinln(dateTimeFormatter.print(now));
很好,并且根据模式打印: 20110131101805 +0100
问题是什么?根据我在 Joda Time 的模式语法,该模式似乎是正确的。
谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,如果您希望它解析该值,您的模式应该使用“HH”而不是“hh”。其次,您还需要在值中包含秒。
例如
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.
问题是您在 200906031633 -0300 中缺少秒数。如果我添加秒数,如下所示:(200906031633"00" -0300)
The problem is that you are missing seconds in the 200906031633 -0300. It works if I add seconds to that as shown below: (200906031633"00" -0300)