Which one is the most efficient in handling and formatting dates, and also avoids unnecessary dependencies on third-party components?
-
1Use the Java 8 date/time APIs, available on a wide range of devices through [desugaring](https://developer.android.com/studio/write/java8-support-table). Joda-time is a third-party component. – CommonsWare Sep 14 '21 at 15:47
-
I considered voting to close this as opinion-based, but decided not to. The answer is not that opinion-based: use java.time, the modern Java date and time API. – Ole V.V. Sep 15 '21 at 03:32
1 Answers
TL;DR
Undoubtedly, java.time
, the modern Date-Time API, and part of the standard library, is the most recommended option as of now.
java.util
Date-Time API and their formatting API, SimpleDateFormat
:
The java.util
Date-Time API and their formatting API, SimpleDateFormat
(which extends java.text.DateFormat
) are outdated and error-prone. It is recommended to stop using them completely and switch to java.time
, the modern Date-Time API*.
Joda-Time API:
Quoted below is a notice from the home page of Joda-Time:
Note that from Java SE 8 onwards, users are asked to migrate to java.time (JSR-310) - a core part of the JDK which replaces this project.
Moreover, Joda-Time API is not the standard API of Java; rather, it's a 3rd party library.
java.time
API:
This is the modern Date-Time API and was introduced with Java SE 8, as part of JSR-310 implementation, to model ISO_8601 standards. You can learn about java.time
API from Trail: Date Time.
* For any reason, if you have to stick to Java 6 or Java 7, you can use ThreeTen-Backport which backports most of the java.time functionality to Java 6 & 7. If you are working for an Android project and your Android API level is still not compliant with Java-8, check Java 8+ APIs available through desugaring and How to use ThreeTenABP in Android Project.

- 71,965
- 6
- 74
- 110
-
I have seen many questions and comments related to this. I wonder why java.util and SimpleDateFormat have not been deprecated yet. – LabGecko Jul 26 '23 at 12:31
-
1@LabGecko, most of the things in [java.util.Date](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html) are already deprecated. – Arvind Kumar Avinash Jul 26 '23 at 12:58