Why the current year in the date saved as 3912?

前端 未结 2 1030
梦谈多话
梦谈多话 2021-01-11 19:25

to get the current date and time

final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calend         


        
2条回答
  •  没有蜡笔的小新
    2021-01-11 20:02

    From Date.setYear(int) description: Sets the gregorian calendar year since 1900 for this Date object. Thus, 1900 + 2012 = 3912.

    But calendar.get(Calendar.YEAR) returns exact year number 2012. So this inconsistency of API causes your issue. But anyway Date.setYear(int) is deprecated, thus, it is better to use Calendar object for date calculations.

提交回复
热议问题