yves amsellem
yves amsellem

Reputation: 7244

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:

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

Upvotes: 1

Views: 921

Answers (1)

Valdis R
Valdis R

Reputation: 2115

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";
}

Upvotes: 2

Related Questions