java - JodaTime 中格式错误的时区

标签 java datetime date jodatime

我有以下使用 Joda 时间的片段:

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("HH z")
String dateTime = dateTimeFormatter.print(new DateTime())
println DateTime.parse(dateTime, dateTimeFormatter)

但它会抛出 IllegalArgumentException:

Invalid format: "16 EDT" is malformed at "EDT"

我错过了什么?

编辑:非常适合 DateTimeFormat.forPattern("HH")

最佳答案

根据DateTimeFormat javadoc , 时区名称 ('z') 无法解析。

编辑: 要解析时区,我会考虑使用“Z”和实际时区偏移量(例如 -0500 表示东部)。您可能还想查看 DateTimeFormatter 中的 withOffsetParsed() 方法——例如。 dateTimeFormatter.withOffsetParsed().parseDateTime("16 -0500");

关于java - JodaTime 中格式错误的时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10939471/

相关文章:

java - 我想在 Java 中获取格式化的日期

Javascript 日期意外自动更新

java - Jbutton setTooltip() 作为 ImageIcon?

python - 如何使用 Python 获得准确的 UTC 时间?

php - 周日和周六的 php 日期?

python - 在不循环的情况下将日期时间系列转换为 Pandas 中的字符串

python - 将字符串日期时间转换为 Pandas 日期时间

java - 在eclipse中打包项目

java - 为什么切换会导致无法解决错误?

java - 如何使用 JNI 在 C 中获取原始 Android 相机缓冲区?