-2

The code I've got should convert the date of birth input to DD/MM/YYYY format, which it does but for example when I input 20/08/2000 it sees the date as 3rd January.

System.out.println(this.dob);
DateFormat dateF = new SimpleDateFormat("dd/MM/YYYY");
Date birth = dateF.parse(this.dob);
System.out.println(birth);

Which outputs

20/08/2000
Mon Jan 03 00:00:00 GMT 2000
theglobin
  • 33
  • 6
  • Why can't people learn the difference between `yyyy` and `YYYY`? Or why they don't even bother to recheck if their pattern is correct? Annoying. – Tom Apr 07 '16 at 20:41

1 Answers1

4

Using capital Ys in your format means something called the "week year".

Instead, use lowercase ys in your format, which means the year as you'd expect.

new SimpleDateFormat("dd/MM/yyyy");
rgettman
  • 176,041
  • 30
  • 275
  • 357
  • When in August, the year and the week year are the same. The week year is the year that the week number belongs to; only around New Year may it deviate from the year (for instance if week 52 of the previous year extends into January). – Ole V.V. Apr 07 '16 at 20:43
  • 2
    @OleV.V. That may be true, but changing to `yyyy` corrects the output to the proper date. – rgettman Apr 07 '16 at 20:45