Why were most java.util.Date methods deprecated?

后端 未结 5 992
野趣味
野趣味 2020-11-27 18:36

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

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 19:19

    I don't know the official reason why it has been deprecated, but as far as I can tell GregorianCalendarand Joda-Time support operations on dates, meaning that you can add, for instance, a day to a date and have its month and year updated accordingly.

    For instance, say you want to compute the day after the current date and today is May 31st; with java.util.Date, you just have getDays() +1, which returns 32, and you have to handle the knowledge that the current month doesn't have 32 days by yourself; with GregorianCalendaror Joda.time, adding a day to May 31st results in an object representing June 1st, hiding the complexity from your sight.

提交回复
热议问题