开发者

GWT DateTimeFormat throws IllegalArgumentException when date value contains « Z »

Parsing a date containing « Z » — timezone indicator — fails, even if the format is well seted. What's the problem?

The following code throws an IllegalArgumentException:

DateTimeFormat
.getFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.parse("2010-12-06T10:26:52.011Z");

This one works开发者_StackOverflow社区:

DateTimeFormat
.getFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.parse("2010-12-06T10:26:52.011");


GWT doesn't understand 'Z' (for Zulu TimeZone) as GMT. If you change the trailing Z in your first example to GMT it works fine.

if (s.endsWith("Z")) {
  //  strip off the last 'Z' and replace with GMT timezone information
  s = StringUtils.chop(s) + "GMT-00:00";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜