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.