[Solved] Why I obtain a wrong result when I create a new Date starting from the year, the month and the day in this Java application? [duplicate]


The Date Javadoc notes

  • 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.

To get the correct Date with the deprecated Date constructor, it would need to be something like new Date(birthYear - 1900, birthMonth - 1, birthDay); but I would prefer LocalDate like

int birthYear = 1984;
int birthMonth = 4;
int birthDay = 12;
LocalDate ld = LocalDate.of(birthYear, birthMonth, birthDay);
System.out.println(ld);

Output is

1984-04-12

solved Why I obtain a wrong result when I create a new Date starting from the year, the month and the day in this Java application? [duplicate]