java - 使用 joda-time 解析包含时区的日期字符串

标签 java jodatime

我正在尝试使用 joda 时间解析日期字符串,不幸的是我找不到解析时区的方法。

这是我的最新尝试:

String s = "2013-09-20 13:23:50 Etc/GMT";
DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss ZZZ").parseDateTime(s)

结果

java.lang.IllegalArgumentException: Invalid format: "2013-09-20 13:23:50 Etc/GMT" is malformed at "Etc/GMT"

我的模式错误在哪里?

最佳答案

您应该使用2.0或更高版本的Joda-Time库。
此功能已在版本 2 中添加。
请参阅release notes 1.6 -> 2.0。

  • Allow 'Z' and 'ZZ' in format patterns to parse 'Z' as '+00:00' [2827359]

  • Support parsing of date-time zone IDs like Europe/London

  • Support parsing of date-time zone names like "EST" and "British Summer Time" These names are not unique, so the new API methods on the builder require you to pass in a map listing all the names you want to be able to parse. The existing method is unaltered and does not permit parsing.

关于java - 使用 joda-time 解析包含时区的日期字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19120569/

相关文章:

java - 如何为 joda DateTime 对象指定时区?

java - 带小时和秒的 RRULE google-rfc-2445

java - 如何改进这种从 ArrayList 中删除重复项的方法,使其比 O(n2) 更有效

java - 无法运行 jar 文件 : Could not find or load main class Hello

java - InetAddress 类中的 isReachable 问题

java - 通过java运行Shell脚本

java - 使用 Joda API 解析日期

java - 如何使用 JodaTime 获取一年中的天数?

java - Java中的Joda-Time间隔是否有替代方法,它可以作为结束时间

java - 无法删除属于 @ManyToOne 关系的 JPA 实体