开发者

GWT DateTimeFormat throws IllegalArgumentException when date value contains « Z »

开发者 https://www.devze.com 2023-02-09 14:29 出处:网络
Parsing a date containing « Z » — timezone indicator — fails, even if the format is well seted. What\'s the problem?

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

精彩评论

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