为什么大多数java.util.Date方法被弃用? [英] Why were most java.util.Date methods deprecated?

查看:843
本文介绍了为什么大多数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方法被弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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