Why were most java.util.Date methods deprecated?

后端 未结 5 988
野趣味
野趣味 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:18

    Here's a good answer straight from Oracle: http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html

    A long-standing bugbear of Java developers has been the inadequate support for the date and time use cases of ordinary developers.

    For example, the existing classes (such as java.util.Date and SimpleDateFormatter) aren’t thread-safe, leading to potential concurrency issues for users—not something the average developer would expect to deal with when writing date-handling code.

    Some of the date and time classes also exhibit quite poor API design. For example, years in java.util.Date start at 1900, months start at 1, and days start at 0—not very intuitive.

    ... java.util.Date represents an instant on the timeline—a wrapper around the number of milli-seconds since the UNIX epoch—but if you call toString(), the result suggests that it has a time zone, causing confusion among developers.

提交回复
热议问题