14

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?

Community
  • 1
  • 1
Sai Ye Yan Naing Aye
  • 6,622
  • 12
  • 47
  • 65

1 Answers1

31

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.

Benny Bottema
  • 11,111
  • 10
  • 71
  • 96
Jesper
  • 202,709
  • 46
  • 318
  • 350
  • 5
    Update: 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. – Jesper May 19 '14 at 07:00
  • Currently I use Java 7 on my project with Joda Time API. But I will try to test Java 8's new date and time API.Anyway Thanks man – Sai Ye Yan Naing Aye Jun 04 '15 at 01:05
  • 1
    @SaiYeYanNaingAye There's now also a [backport of the Java 8 date and time API](http://www.threeten.org/) available - a separate library that you can use with Java 7, which will give you the new Java 8 date and time API (with minor differences). – Jesper Jun 04 '15 at 07:05