Geeks With Blogs

The Life and Times of a Dev Yes, we're really that weird

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().

Posted on Wednesday, September 20, 2006 11:15 AM Work | Back to top


Comments on this post: Ugh--more Java

# re: Ugh--more Java
Requesting Gravatar...
Thanks for the idea. I might as well consider using it. - Morgan Exteriors
Left by Jon Curtney on Feb 10, 2017 11:12 AM

Your comment:
 (will show your gravatar)


Copyright © Robert May | Powered by: GeeksWithBlogs.net