Dustin Marx is a software developer who enjoys identifying and using the correct tool for the job. In addition to writing software and writing a blog on software development, Dustin occasionally presents at conferences and writes articles. Dustin is a DZone MVB and is not an employee of DZone and has posted 234 posts at DZone. You can read more from them at their website. View Full User Profile

How Badly Do We Want a New Java Date/Time API?

  • submit to reddit

The current Java.net poll question is, "How critical is it for JSR-310 (new Date and Time API) to be implemented in Java 8?" At the time of my writing of this post, nearly 150 respondents have voted and an overwhelming percentage have answered either "Very" (53%) or "It would be nice, but we can get by using the current classes" (22%). With 3/4 of the respondents feeling that it would either "be nice" or is "very important" to get a new Java Date/Time API, I think it's safe to say that Java's current Date and Calendar approach has not grown on us. Perhaps my biggest surprise so far with the survey results is that 2% of the respondents have stated, "I prefer the current date and time classes." Maybe that's from the people who wrote those classes?

I tend to use Java's date/time/calendar APIs off and on. When I use them, I really don't like them, but do start to tolerate them. I begin to forget how much I loathe them until I use them again. I recently helped a colleague familiar with Java (but not with the date/time APIs) to understand how to do some Date/Calendar/String manipulation and presentation. Explaining this mess out loud to him made the ridiculous difficulty of using these too-flexible APIs even more obvious to me. I could see on his face that he was thinking I was either kidding him or didn't know what I was talking about. Although I've gotten to the point where I can make them make do, it's much more difficult than it should be.

Much has been written about the woes of date/time handling in Java. Rob Sanheim wrote in 2006 about date/time-related problems in three of his Top Five Worst APIs in Java (Calendar, Date, and DateFormat/SimpleDateFormat). Java's Date-handling is focused on in Cameron Purdy's 2005 post The Seven Habits of Highly Dysfunctional Design. Tero Kadenius reminded us in the 2011 post Handling dates in Java that "The date/time API in Java is notoriously painful to work with." The aptly named post Java Dates Still Suck was published in 2009.

The current Java.net survey confirms my feeling after working with numerous Java developers and after reading many blogs and articles that the vast majority of Java developers are anxious to get a better standardized way of handling dates and times in Java.

Published at DZone with permission of Dustin Marx, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Lance Semmens replied on Mon, 2012/03/12 - 4:18am

You could just use joda time like the rest of us have been doing for years :)


matt inger replied on Mon, 2012/03/12 - 9:42am

And how about some proper design like making the formatter classes threadsafe?  They have no reason to have internal state related to what they are parsing. 


Another thing that always annoyed me is they never genericized the Format class (I'll delay philosophical debate about whether this should be an interface or not), nor does the DateFormat class deal with Calendar objects.


The big thing i fear that will happen is that they will have this JSR and take concepts from Joda-time, and do an incomplete implementation, like they did with JPA (I still can't use JPA without resorting to specific hibernate annotations) and CDI. 

Byron Palmer replied on Mon, 2012/03/12 - 11:22am

I use joda time and it works great, and I only use Date to interface with those things that require date. Date and Calendar are so poor and do so many things wrong that they are useless and actually dangerous. I can't tell you the hours that have been lost by programmers trying to use them to track every hour of every day.

 Although joda time works and works well, it would be nice if Date and Calendar were replaced in all the places including sql with a real date and time classes.

 Anyone who says that Date and Calendar are fine should not be allowed to program, or should become .NET programmers. 

Varun Tamiri replied on Mon, 2012/03/12 - 7:34pm


Is there any API to get Age, if I give DOB(Date Object or String format,dd/mm/yyyy)


Andy Jefferson replied on Tue, 2012/03/13 - 1:20pm in response to: matt inger

The big thing i fear that will happen is that they will have this JSR and take concepts from Joda-time, and do an incomplete implementation
Isn't that why the JSR310 project is there to accept your input? They have asked more than once on public websites for input, about what people are missing from their current iteration. This JSR has been going on since 2007, and has provided snapshots at frequent intervals

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.