为什么大多数java.util.Date方法被弃用?

编程入门 行业动态 更新时间:2024-10-17 19:25:35
本文介绍了为什么大多数java.util.Date方法被弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当您查看java.util.Date类的javadoc时,大多数方法已被弃用。为什么这样做?

When you look at the javadoc of the java.util.Date class, most of the methods are deprecated. Why was this done?

推荐答案

嗯,有两个相关的原因。日期和时代概念的执行情况非常差,它被 Calendar 类替换。

Well, for two related reasons. It was a very poor implementation of the concept of Dates and Times and it was replaced by the Calendar class.

尽管有一个改进,但是 Calendar class也是很有必要的,所以对于严重的日期/时间工作,每个人都建议使用 Joda-Time 。 Java 8 带来了新的 java.time。* package ,灵感来自于Joda-Time,由 JSR-310 ,旨在取代旧的日期/日历课程。

The Calendar class, although an improvement, leaves a lot to be desired as well, so for serious Date/Time work, everyone recommends Joda-Time. Java 8 brings the new java.time.* package, inspired by Joda-Time, defined by JSR-310, and intended to supplant the old Date/Calendar classes.

编辑:针对为什么实施不好的具体问题,有很多原因。 JavaDoc总结如下:

In response to the specific question of why the implementation is poor, there are many reasons. The JavaDoc sums it up as follows:

不幸的是,这些功能的API不适合国际化。

Unfortunately, the API for these functions was not amenable to internationalization.

除了这种一般的缺陷(其中包括缺少时区组件以及日期格式更好的问题在 DateFormat 中处理,并且无法使用非公历日历表示),有一些具体问题真的伤害了 Date 课程,其中包括该年份与普通时代年份相差1900年。

In addition to this general deficiency (which covers issues like the lack of a Time Zone component as well as the date formatting which is better handled in DateFormat and the inability to have a non-Gregorian calendar representation), there are specific issues which really hurt the Date class, including the fact that year is presented in an offset of 1900 from Common Era year.

日历它自己的问题,但即使早在JDK 1.1,显然 java.util.Date 不会削减它。即使 Calendar 可以说是最差的JDK API,直到版本7尝试解决它。​​

Calendar has its own problems, but even as early as JDK 1.1 it was obvious that java.util.Date was not going to cut it. Even though Calendar is arguable the worst JDK API, it has taken until version 7 to attempt to address it.

更多推荐

为什么大多数java.util.Date方法被弃用?

本文发布于:2023-11-10 02:49:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574135.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   util   java   被弃用   Date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!