代码:
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/