Joda Time vs Java Time

Although Joda is feature rich and more sophisticated than standard Java time, it may not always be the best thing to use. How do I decide if I should use Joda Time or Java Time in any Java code?

Is there some kind of guideline which tells us how to pick the right one depending on our requirements?

4

Java 8 and Later

Use the Date & Time API included in java.time.*. It’s heavily influenced by Joda Time. In fact the main author is Stephen Colebourne, the author of Joda Time.

Prior to Java 8

Joda Time is such an improvement over the Java legacy time library (java.util.Date and java.util.Calendar) that it is almost always the right choice, apart from the following exceptions:

  1. When it is difficult or undesirable to add third party dependencies to your project

  2. When its use in a public interface would cause issues, e.g. getting an ORM to handle both java and Joda time fields

However, in the case of 2) it would still be better to use Joda internally if possible.

4

Note that on the Joda-Time website it states:

The standard date and time classes prior to Java SE 8 are poor. By tackling this problem head-on, Joda-Time has become the de facto standard date and time library for Java. Note that from Java SE 8 onwards, users are asked to migrate to java.time (JSR-310).

The main contributor to Joda-Time, jodastephen, is also the main contributor for JSR-310, as can be seen on the GitHub repository associated with http://www.threeten.org/. By the way, jodastephen has also a SO handle …

I think it is safe to state that we can feel comforted and safe with the new Date and Time API as provided in Java 8 onward.

Some additional references:

  • Official JCP-310 webpage
  • Joda-Time
  • Three-Ten
  • java.time.* Javadoc
  • Date Javadoc

The Java standard date API is so fundamentally broken that I have often considered simply adding Joda Time to the library extensions of the JVM so that it loaded on the classpath by default with the rest of the Java API.

If you have ever been tasked with retrofitting internationalization and time zones into a legacy Java application and have attempted to use the standard Java API alone, you will understand what I mean. I was able to turn thousands of asinine lines of code into less than a hundred. The productivity boost is inconceivable.

Further the standard Date API is not intuitive, where the fluid Joda API can be picked up in hours not weeks. Your analogy of trying to get to the island that is two miles away, is more akin to the following.

1) A motorboat that will get you to the island in only 6 minutes.

Or…

2) A makeshift bamboo raft tied together with vines during a hurricane steered by a crazy guy whose best friend is a volleyball.

As other answers have stated, the few drawbacks such as the ORM are even becoming non-existent as Hibernate now has plugins that allow for Joda type bean properties to be mapped to database date/time fields. JPA might also have an answer for this as well.

If your desire is for your application to have a minimalist footprint as a desktop application as it pertains to disk space then perhaps Java is not even the right language choice.

1

One more point:
Java-Time (i.e. Date) is not ThreadSafe but JodaTime is.
So JodaTime is preferred when requirements like

  • MultiThreaded Environment accessing the common resources
  • Centralized Time Synchronization like situations

Or else for simple applications Java-Time is okay.

4

The java.time framework replaces both legacy date-time classes and Joda-Time

Update: The old date-time classes shipped with the earliest versions of Java are now legacy, officially supplanted by the java.time classes built into Java 8, Java 9, and later.

Date, Calendar, SimpleDateFormat, and the java.sql.* date-time classes should all be avoided. There is never a need to use these confusing, troublesome, poorly-designed classes. They are entirely replaced by java.time classes. Their only purpose now is for maintaining existing old code. When interfacing with old code, you can convert to/from java.time by calling new methods added to the old classes. For more info on converting, see: Convert java.util.Date to what “java.time” type?.

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes. The Joda-Time project inspired the java.time framework. Both are led by the same man, Stephen Colebourne. You can think of java.time as an rewrite/redesign of Joda-Time, all new code but using what had been learned over the years from building the industry’s first comprehensive and sophisticated date-time library.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations.

Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP (see How to use…).

The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật