It seems that the new java.time
API offers everything from java.util.Date
and much more.
Is there any reason to use java.util.Date
when the newer java.time
API is there since Java 8?
Should java.util.Date
and java.util.Calendar
be avoided completely?
相关问题
- Which class does LongAdder extends?
- Single element in multiple groups when grouping wi
- JVM crashes with problematic frame [libjvm.so+0x7f
- Why doesn't for-each method in java not throw
- Returning from Java Optional ifPresent()
相关文章
- ceil conterpart for Math.floorDiv in Java?
- Do JDK classes have any further specifications bey
- java.time.ZonedDateTime.parse and iso8601?
- Java “static import” vs. “import static” in Java 8
- Will java allow to use functional interfaces as me
- How to enable “type information” for streams retur
- Unable to open keystore in AndroidStudio - “Redund
- JSTL Date comparison
Short answer: The new API
java.time
is way better than the old world withjava.util.Date
andjava.util.Calendar
. So yes, the new API should be preferred in new code.For a quick overview: Once I had written a comparison of features in table form for various date-time-libraries. There is almost no feature which
java.time
is missing but exists in the old world:FieldPosition
(used in Swing-componentFormattedTextField
)About deprecation: Although most parts of
java.util.Date
are deprecated since Java 1.1, the class itself (andjava.util.Calendar
, too) are not officially deprecated, just declared as de facto legacy. The support of the old classes is still important for the goal of backwards compatibility with legacy code. So Oracle will probably not stop the support at any time in the future. But maybe Oracle will apply more sophisticated deprecation strategies.Future development: It is interesting that the release of Java-8 has not only incorporated a completely new date/time-API (
java.time
) but also seen some few enhancements tojava.util.Calendar
, for example Calendar.Builder or SHORT_STANDALONE etc. Well, I can only speculate but this also seems to indicate that Oracle is not willing to stop the support of the old API in the near future.