« - »

It’s Joda Time!

15 July 2010

For the longest time now I have been WWWAAAYYY too busy to even think about doing any blogging, but hopefully that is all starting to change now. Things are starting to settle down a little, and I should have a wee bit more time.

Speaking of time (nice segue, no?), I have been having fun with ISO 8601 dates and times for quite a while. On the sever side, I have just been using plain old java.util.Date and java.text.DateFormat. Then I found this:

Joda Time – Java date and time API

According to their home page, “Joda-Time has been created to radically change date and time handling in Java. The JDK classes Date and Calendar are very badly designed, have had numerous bugs and have odd performance effects.”. At this point, I have only played around with DateTime, but I have to say that I like it so far.

One thing that I never did like about DateFormat was that the Time Zone component never rendered out with the colon (“:”) in between the offset hours and offset minutes. I had to add this code:

    String string = FORMAT.format(date);
    return string.substring(0, string.length() - 2) + ":" +
         string.substring(string.length() - 2);

… to this back in the day. With Joda Time, you can accomplish the same thing with this (assuming that “date” is a Joda Time DateTime object):

    String string = date.toString();

It’s one of my new standards!


http://blog.restafarian.org/2010/07/its-joda-time/

Leave a reply

You must be logged in to post a comment.