parsing - DateTimeFormat.parse() 失败

标签 parsing gwt datetime-format

代码:

    DateTimeFormat dateFormat = DateTimeFormat
            .getFormat("EEE MMM dd HH:mm:ss zzz yyyy");

    Date date = dateFormat.parse("Wed May 30 18:33:22 PDT 2012");

结果:

Uncaught java.lang.IllegalArgumentException: Wed May 30 18:33:22 PDT 2012

为什么?

我已经对照the docs检查并仔细检查了我的模式。 。将模式插入 SimpleDateFormat tester也给出了预期的结果,尽管这显然不是一个结论性的测试。

最佳答案

根据docs,对日期的解析支持有限。你提到:

The time zone support for parsing is limited. Only standard GMT and RFC format are supported. Time zone specification using time zone id (like America/Los_Angeles), time zone names (like PST, Pacific Standard Time) are not supported.

更具体

In the current implementation, timezone parsing only supports GMT:hhmm, GMT:+hhmm, and GMT:-hhmm.

因此,以下代码可以正常工作:

    DateTimeFormat dateFormat = DateTimeFormat
            .getFormat("EEE MMM dd HH:mm:ss zzz yyyy");
    Date date = dateFormat.parse("Thu May 31 09:45:21  GMT-07:00 2012");
    GWT.log("Date "+date);

关于parsing - DateTimeFormat.parse() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10827179/

相关文章:

java - 如何在Java中基于节点枚举对象?

java - 无法连接到 sqlite 数据库 - _syscall() 中出现内部错误

java - 在 GXT 中,何时为日期触发更改事件

javascript - 如何使用 node.js 生成 utc 时间戳

java - Java 11 (Zulu) 中的 DateTimeFormatter 不适用于 AM/PM 格式

jackson - @JsonFormat 反序列化失败

python - 使用 dateutil.parser.parse 抛出两位数年份日期的 ValueError

使用 perl 的 HTML 解析器

java - 如何用java编写JavaScript解析器

java - 关于在 GWT、GXT、SmartGwt 等中减少代码长度、JS 大小(加载时间)的想法