Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes how to parse a non-standard Date? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to parse a non-standard Date?" Watch "how to parse a non-standard Date?" New topic
Author

how to parse a non-standard Date?

Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
I'm trying to parse a non-standard date string like the following
2008-12-05T10:58:04.197-05:00
. Using a SimpleDateFormat string such as
yyyy-MM-dd'T'HH:mm:ss.SSSZ
won't work because the timezone portion of the date doesn't follow either of the two supported formats. Is there any way to get the formatter to accept this date?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32507
    
214

Phillipe,
How about converting the string to the standard "-0800" first? You could use a string method call to get rid of the last colon.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
    
  10
Yeah, what she said.
Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
Yep. That's what I ended up doing. Just thought there was some more... elegant way to do this. Oh well.

Thanks!
 
Have you checked out Aspose?
 
subject: how to parse a non-standard Date?
 
It's not a secret anymore!