/**
* 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 <code>Date</code> object, as interpreted in the local
* time zone.
*
* @return the year represented by this date, minus 1900.
* @see java.util.Calendar
* @deprecated As of JDK version 1.1,
* replaced by <code>Calendar.get(Calendar.YEAR) - 1900</code>.
*/
@Deprecated
public int getYear() {
return normalize().getYear() - 1900;
}
用这个方法获取年份时是从1900年开始计算的,因此当年份为2009时,得到的结果为109,所以如果要得到最终的年份,要再加上1900。
本文详细解释了Java Date类中的getYear()方法的实现原理,指出其从1900年开始计算年份的原因,并提供了一个简单示例说明如何正确使用此方法获取完整年份。

153

被折叠的 条评论
为什么被折叠?



