java.util.GregorianCalendar sucks
Filed under: Uncategorized, Java
I have seen two bugs lately, which were directly related to the GregorianCalendar:
- GregorianCalendar and XMLGregorianCalendar count the time differently. While XMLGregorianCalendar starts counting the months with ‘1′, the standard GregorianCalendar starts with ‘0′.
- If you use GregorianCalendar.HOUR, this will make the
GregorianCalendar to use a 12-hour clock, which resulted in a bug which only occured after midday.
While these quirks can be considered as must-have knowledge for a Java
developer, they still suck.
As a result of these bugs, I have started introducing Joda-time in some of projects I work on. This is probably not big news for some of you, but it seems that Joda-time is much easier to use.
What are your experiences with Joda-time?
Mar 23, 2008 at 19:50 | Permalink
4 Comments
1. Humphrey Bogus | March 24th, 2008 at 3:20 am
Have used joda time effectively to do elapsed date calcuations for the purposes of valuing financial instruments. (Not hyper-accurate stuff, but date differences measured in months.) Worked very well, solved the problem perfectly, easy to use API. Definitely recommended.
2. ahmetaa | March 24th, 2008 at 3:48 am
jsr-310 is the cure for this.
there is a nice presentation here:
http://parleys.com/display/PARLEYS/JSR+310+-+Date+and+Time+API?showComments=true
3. Michael Easter | March 24th, 2008 at 5:24 am
In my limited experience with Joda time, I think it rocks: it is easy to use and they treat the sticky issues very seriously.
I believe the work from the project will be part of JSR 310 / Java 7.
It reminds me of how log4J was a “slam dunk” for logging, years ago.
4. Ken Rimple | October 6th, 2008 at 3:45 pm
Heh. Yes, the whole time and timezone system for Java is quite antiquated and in need of a rewrite. I’m going to read up on JSR-310.
I do recall having quite a time dealing with TimeZones in a recent engagement. The customer was creating their own timezones with SimpleTimeZone–a class which belies it’s own title. If you have a little time, download the source and read the JavaDoc. Never a more confusing API was written…
Joda Time did look pretty good to me, but we had to create lots of custom timezones and I didn’t see much of an improvement there. Of course, that was a very strange case.
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed