java.util.Date类中的getYear()方法,发现取出来的年份是109,与真实年份差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.
*
* @return the year represented by this date, minus 1900.
* @see java.util.Calendar
* @deprecated As of JDK version 1.1,
* replaced by Calendar.get(Calendar.YEAR) - 1900.
*/
@Deprecated
public int getYear() {
return normalize().getYear() - 1900;
}
用这个方法获取年份时是从1900年开始计算的,因此当年份为2009时,得到的结果为109,所以如果要得到最终的年份,要再加上1900。
博客介绍了Java中java.util.Date类的getYear()方法。使用该方法获取年份时,结果是从1900年开始计算的,如2009年得到的结果为109。若要得到最终年份,需在结果上加上1900,并给出了该方法的相关文档说明。

1万+

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



