I’ve complained about the Java Date API classes before, it’s complicated,difficult to use and the calender class makes accessing methods clunky and well, verbose.

Last week I found Joda-Time, a replacement for the Java Date/Time classes. I played around with it for a week and found Joda-Time has great support for Time Zones and Time Periods which is super handy and easier to read than the JDK classes; it makes it easy to find some date plus/minus a time period, no more mucking around with the Calendar class or TimeZone classes.

Here’s a small example of what Joda-Time can do:

//JDK, adding 15 years to a date
Calendar rightNow = Calendar.getInstance();
rightNow.add(Calendar.YEAR, 15);
Date javaDate = rightNow.getTime();
System.out.println(javaDate.toString());

//Joda Time, adding 15 years to a date
DateTime jodaDate = new DateTime().plusYears(15);
System.out.println(jodaDate.toString());

//Joda Time, changing timezone
DateTime newDate = jodaDate.withZone(DateTimeZone.forID(“US/Eastern”));
System.out.println(newDate.toString());
Play around with Joda-Time and decide for yourself.

Share and Enjoy:
  • del.icio.us
  • Reddit
  • Facebook
  • Identi.ca
  • TwitThis

Related posts:

  1. JSR-310
  2. Java Date and Calendar classes
  3. Design Patterns are missing language features.
  4. Ruby with a C++ Accent

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Search