简体   繁体   English

Java Date输出错误。 为什么?

[英]Java Date output is wrong. Why?

I'am playing with Java Date and can't understand this: 我在玩Java Date,无法理解:

Date myBirth = new Date(1991,01,21);
Log.d("DATE: ", "" + myBirth);

Here I initialized Date object. 在这里,我初始化了Date对象。 Why I get this output? 为什么得到此输出?

DEBUG/DATE:(31693): Sat Feb 21 00:00:00 EET 3891

From the Date docs : 日期文档

  • A year y is represented by the integer y - 1900. 年y由整数y-1900表示。
  • A month is represented by an integer from 0 to 11; 一个月由0到11之间的整数表示; 0 is January, 1 is February, and so forth; 0是一月,1是二月,依此类推; thus 11 is December. 因此11月是12月。

Quoting from the Javadoc of this deprecated constructor of Date: Javadoc中引用以下不推荐使用的Date构造函数:

Parameters:
    year - the year **minus 1900**.
    month - the month between 0-11.
    date - the day of the month between 1-31.

So the output is what you ask, but not what you want. 所以输出就是您要的,而不是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM