Possible Duplicate:
Why does Java’s Date.getYear() return 111 instead of 2011?
I am trying to get the year, month and day form a Date-object, but the following gives me something completely random:
Date d = new Date();
System.out.println(d.getYear() + " - " + d.getMonth() + " - " + d.getDay());
I get: 112 – 9 – 1
Does anyone know why? And do you have a bette apporch? For my program i need the Date objects.
Reading the javadoc of these three methods (which are deprecated and thus shouldn’t be used, BTW) would tell you why:
Use a Calendar to get date fields, and a DateFormat to format dates.