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
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
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.
java.time.LocalDate.of ( 1991 , Month.JANUARY , 21 )
The original date-time classes in Java (Date, Calendar, etc.) are a terribly flawed, bloody awful, horrible mess. Among their many problems: They use insane number for years and months.
Use only the modern java.time classes built into Java 8+ for your date-time work.
The java.time classes use sane numbering. The year 1991 is 1991. Months are 1-12 for January-December.
For January 21, 1991 use the LocalDate class.
LocalDate ld = LocalDate.of ( 1991 , 1 , 21 ) ;
Or use the Month enum.
LocalDate ld = LocalDate.of ( 1991 , Month.JANUARY , 21 ) ;
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.