Sai Ye Yan Naing Aye Sai Ye Yan Naing Aye - 4 months ago 24
Java Question

Differences between java.util.Date and Joda Time APIs


Possible Duplicate:

Should I use Java date and time classes or go with a 3rd party library like Joda Time?




I could use some guidance about when it's worth using Joda Time rather than the basic java.util.Date class. What are the benefits? Does Joda Time let you do anything you can't do with the Date class, or is it just easier to work with or what?

Also, I've seen conflicting info about whether Joda Time is part of the standard API. Is it standard or not?

Answer

Java's standard date and time classes (mainly java.util.Date and java.util.Calendar) have limited functionality and have a number of design problems. The fact that many of the constructors and methods of java.util.Date are deprecated is one indication of this.

Joda Time has a much better thought out API than what's available in Java's standard library. There are classes for timestamps with or without a timezone, classes for holding only a date (year, month, day) or only a time of day, classes for periods, durations and intervals, it supports the ISO 8601 format (which is the standard format in XML documents) and much more.

I'd use Joda Time as my standard date and time library in any project - there really is no reason to use java.util.Date and java.util.Calendar.

Note that in a future release of Java, a new date and time API will most likely be included that's going to look a lot like what's currently available in Joda Time; see Project ThreeTen.

Also see Why Joda Time? on the home page of the Joda Time project.

Also, I've seen conflicting info about whether Joda Time is part of the standard API. Is it standard or not?

No, it isn't part of the standard API.

Update (copied from the comments):

Java 8 is out now, and it has a new date and time API which is similar to Joda Time (see the package java.time). If you're using Java 8, then please use the new date & time API.