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.
Related posts:





Leave a Reply