cqcallaw
cqcallaw

Reputation: 1513

DateTimeFormat.parse() failure

Code:

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

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

Result:

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

Why?

I've checked and doublechecked my pattern against the docs. Plugging the pattern into a SimpleDateFormat tester gives the expected results as well, although that's obviously not a conclusive test.

Upvotes: 2

Views: 1922

Answers (1)

Ganesh Kumar
Ganesh Kumar

Reputation: 3240

Parsing of the date has limited support as per the docs you mentioned:

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.

More specifically

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

So, the following code works fine:

    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);

Upvotes: 4

Related Questions