Re: DateFormat problem

From: Jonas Kongslund (dont_at_mail.me.at.all)
Date: 11/04/03


Date: Tue, 04 Nov 2003 16:29:06 +0100

David Rasmussen wrote:

> Jonas Kongslund wrote:
>>
>> The pattern looks fine. Your example is wrong: replace CET with GMT.
>>
>
> System.out.println(
> new SimpleDateFormat(
> "EEE, dd MMM yyyy HH:mm:ss z"
> ).parse(
> "Sun, 12 Oct 2003 16:25:01 GMT"
> )
> );
>
> Gives the same ParseException.

Works for me. I'm using JDK 1.4.1_02.

> Well, I am not exactly implementing HTTP. I just used it as an example.
> I want to be able to parse the original string that I posted. Surely
> Java can parse dates that are in CET (or any other time zone)?

I just found out that it depends on your JDK version. SimpleDateFormat uses
java.util.TimeZone, which may or may not support other three-letter time
zone IDs than "GMT". The javadoc for TimeZone bundled with JDK 1.4.1 states
the following:

<quote>
Three-letter time zone IDs
 For compatibility with JDK 1.1.x, some other three-letter time zone IDs
(such as "PST", "CTT", "AST") are also supported. However, their use is
deprecated because the same abbreviation is often used for multiple time
zones (for example, "CST" could be U.S. "Central Standard Time" and "China
Standard Time"), and the Java platform can then only recognize one of them.
</quote>

Try running this code:

String[] ids = TimeZone.getAvailableIDs();
for (int i = 0; i < ids.length; i++) {
  System.out.println(ids[i]);
}

-- 
Jonas Kongslund


Relevant Pages

  • Re: TimeZone.getID() across different jdk versions
    ... from server running jdk 1.4.* to my java client running lower version of jdk. ... you might consider sharing your own time zone database between the two applications. ...
    (comp.lang.java.programmer)
  • Re: SimpleDateFormat parse changes time zone
    ... but that's not set in stone. ... It seems like the parser is changing the time zone from EDT to EST, ... JDK 1.4.2_11. ...
    (comp.lang.java.programmer)
  • Re: SimpleDateFormat challenge
    ... I ran it as junit test under jdk 1.5: ... On my system, the sdf fails to parse the string on 1.4.2, 1.5 and 1.6. ...
    (comp.lang.java.programmer)