This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes SimpleDateFormat not parsing valid RFC822 date? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "SimpleDateFormat not parsing valid RFC822 date?" Watch "SimpleDateFormat not parsing valid RFC822 date?" New topic
Author

SimpleDateFormat not parsing valid RFC822 date?

Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177


Line 3 fails even though I think 2009-08-07T15:00:00.000Z is a valid timestamp. (See http://tools.ietf.org/html/rfc3339#section-5.8) Am I doing something wrong, or is this a bug in SimpleDateFormat?
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
It also doesn't support dates whose time zone adjust is in the format -08:00, which is also part of RFC822.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The API documentation for SimpleDateFormat says exactly what parsing will accept as a time-zone when the "Z" character is used in the format string. I don't see where it says it will accept a "Z" as a time-zone. And it doesn't mention accepting colons either. So I would say the class is working according to its published specifications.
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
It specifically says that Z is for an RFC822 time zone:
http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
"Z Time zone RFC 822 time zone -0800"

Their sample is in the offset format, sans the colon. "Z" as a suffix for Zulu time is certainly part of RFC822. I guess Sun's implementation is non-standard, in that it doesn't appear to comply with RFC822. I wonder what standard they were coding against, or what feeds can use their format? The data I'm reading complies with the published RFC822 format, so it's a bummer I apparently can't use SimpleDateFormat to parse it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If your gripe is that the documentation says "RFC822 time zone" but doesn't provide a full implementation of RFC822, then you're absolutely correct. But I would expect you aren't the first person to run into this... have you googled for third-party classes which might work better?
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Their lack of support for the colon is non-standard too. I did Google for other parsers, but didn't find any within the time span of my patience. Apache Commons has one, but it only formats -- it doesn't parse. Oh well.
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Paul Clapham wrote:If your gripe is that the documentation says "RFC822 time zone" but doesn't provide a full implementation of RFC822, then you're absolutely correct. But I would expect you aren't the first person to run into this... have you googled for third-party classes which might work better?


By the way, I'm not trying to gripe -- I'm just confused by the behavior and thought I might have made a mistake in my parse pattern, or misunderstood the documentation. I'm still not sure if their documentation is wrong, or their implementation. Is there some place on the Sun site where I can document this apparent inconsistency?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Here's the place to report bugs: http://bugs.sun.com/

I wouldn't be at all surprised to find that your issue is already in that database, though. Sun doesn't seem to be very proactive at fixing small things like that.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The time / date / calendar APIs in Java are unfortunately not great on some points, and that's why Joda Time is a very popular open-source library to deal with time and date values better.

There's an initiative, JSR-310, for a new standard time / date / calendar API for Java, which is based on Joda Time - so something like Joda Time will probably become standard in a future version of Java.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

From what I've seen and read, Java 7 is supposed to implement that JSR. However I had a quick look at the Joda API and their DateTimeFormat class doesn't seem to support all of RFC 822 either.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SimpleDateFormat not parsing valid RFC822 date?
 
Similar Threads
Date conversions
A SimpleDateFormat for ISO 8601
comparing dates
Strange problem in date calculation (IS IT BUG!!!)
Java date conversion confusion...