java.util.Date和java.util.Calendar是否已被弃用? [英] Are java.util.Date and java.util.Calendar deprecated?

查看:523
本文介绍了java.util.Date和java.util.Calendar是否已被弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎新的 java.time API提供了来自 java.util.Date 等所有内容。

当较新的 java.time 时,有没有理由使用 java.util.Date 自Java 8以来API是否存在?
应该完全避免 java.util.Date java.util.Calendar

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?

推荐答案

简答:新API java.time 使用 java.util.Date java.util.Calendar ,比旧世界更好。所以是的,在新代码中首选新API。

Short answer: The new API java.time is way better than the old world with java.util.Date and java.util.Calendar. So yes, the new API should be preferred in new code.

快速概述:一旦我写了表格形式的功能比较。几乎没有 java.time 缺少的功能,但在旧世界中存在:

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:


  • 可配置gregorian / julian cutover

  • 打印基于类 FieldPosition (用于Swing-component FormattedTextField

  • configurable gregorian/julian cutover
  • printing based on the class FieldPosition (used in Swing-component FormattedTextField)

关于弃用尽管<$ c $的大部分内容c> java.util.Date 自Java 1.1以来已弃用,类本身(以及 java.util.Calendar )也未正式弃用,刚刚被宣布为事实上的遗产。对于向后兼容遗留代码的目标,旧类的支持仍然很重要。因此Oracle可能不会在将来的任何时候停止支持。但也许Oracle会应用更多复杂的弃用策略

About deprecation: Although most parts of java.util.Date are deprecated since Java 1.1, the class itself (and java.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.

未来发展:有趣的是,Java-8的发布不仅包含了全新的日期/时间API( java.time )但也看到了对 java.util.Calendar 的一些增强,例如 Calendar.Builder SHORT_STANDALONE 等。好吧,我只能推测,但这似乎也表明甲骨文不愿意在不久的将来停止对旧API的支持。

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 to java.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.

这篇关于java.util.Date和java.util.Calendar是否已被弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆