Alex Kulakovsky
Alex Kulakovsky

Reputation: 13

Java Date output is wrong. Why?

I'am playing with Java Date and can't understand this:

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

Here I initialized Date object. Why I get this output?

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

Upvotes: 0

Views: 105

Answers (2)

Andrew Clark
Andrew Clark

Reputation: 208475

From the Date docs:

  • A year y is represented by the integer y - 1900.
  • A month is represented by an integer from 0 to 11; 0 is January, 1 is February, and so forth; thus 11 is December.

Upvotes: 3

fvu
fvu

Reputation: 32953

Quoting from the Javadoc of this deprecated constructor of 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.

Upvotes: 1

Related Questions