Getting Year, Month and Date in Android

I am trying to get today's Year, Month and Date using following code;

Calendar calendar = Calendar.getInstance();

int thisYear = calendar.get(Calendar.YEAR);
Log.d(TAG, "# thisYear : " + thisYear);

int thisMonth = calendar.get(Calendar.MONTH);
Log.d(TAG, "@ thisMonth : " + thisMonth);

int thisDay = calendar.get(Calendar.DAY_OF_MONTH);
Log.d(TAG, "$ thisDay : " + thisDay);

But it gives "2012 for year 1 for month and 28 for date" which is not today's date. What I have done wrong?


Would I be correct in assuming this is running on a Emulator? If so, Set the emulator date correctly, and it should be correct.

From memory, that code should do what you expect.


Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
calendar.get(Calendar.YEAR)