The Life and Times of a Dev

Yes, we're really that weird
posts - 179, comments - 302, trackbacks - 106

My Links

News

Twitter









Tag Cloud

Archives

Post Categories

Play

Work

Ugh--more Java

Something as simple as Date parsing in Java is a nightmare.

Suppose the following:

users can pass in dates, and I may not know what format the dates are in.  For example, I may get MM/dd/yyyy or M/d/yyyy or MM/dd/yyyy hh:mm:ss or whatever.

In Java, there is no easy way to parse all of those formats.  They say, “Use the SimpleDateFormatter”, but the simple date formatter throws an exception when you try to parse a date such as 06/01/2006 and says it's an invalid date.  So if you create a SimpleDateFormatter with a pattern of “MM/dd/yyyy”, EVERYTHING outside of that pattern now breaks (such as MM/dd/yyyy hh:mm:ss).  ARGH!

If you know, and can enforce, the format before time, this isn't a big deal, but it FORCES you to only allow certain formats, which is painful.

Microsoft got this right with DateTime.Parse().

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Wednesday, September 20, 2006 11:15 AM | Filed Under [ Work ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: