Is the calendar .YEAR, .MONTH, DAY_OF_MONTH different from date.getDay (), etc.?

I get it:

Calendar c = new GregorianCalendar();
mYear=c.get(Calendar.YEAR);
mMonth=c.get(Calendar.MONTH);
mDay=c.get(Calendar.DAY_OF_MONTH);

And this:

Date d = c.getTime();
int day = d.getDay();
int month = d.getMonth();
int year= d.getYear();

Different numbers multiply, is there some kind of initialization that I don't see? I care because I use ORMLite and try to store dates in a database that is a Date object, but Date is outdated and therefore I try to use a calendar, but it doesn’t seem so simple, because the above code leads to different answers for day, month and year.

+5
source share
1 answer

Date.getYear(), getMonth() and getDay() are deprecated and specifically asked to use Calendar.get ()

The reason you get different answers is two times.

getDay() , - getDate()

getYear() - 1900

API

. JDK 1.1, Calendar.get(Calendar.YEAR) - 1900.

http://download.oracle.com/javase/6/docs/api/java/util/Date.html#getYear%28%29

+11

All Articles