Why does Java's Date.getYear() return 111 instead of 2011?

后端 未结 6 2021
抹茶落季
抹茶落季 2020-11-28 09:25

I am having a bit of trouble parsing a string date to a Date object. I use a DateFormat to parse the string, and when I print the value of the date

6条回答
  •  臣服心动
    2020-11-28 09:49

    Javadoc to the rescue:

    Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) - 1900.

    Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

    You should not use deprecated methods. Deprecated methods are methods which should not be used anymore. But whatever the method you're using, read its javadoc to know what it does.

提交回复
热议问题