Reputation: 4324
Which one is the most efficient in handling and formatting dates, and also avoids unnecessary dependencies on third-party components?
Upvotes: 3
Views: 795
Reputation: 79075
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*.
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.
Upvotes: 4