Adham Adham - 3 months ago 6
Java Question

Why getting the wrong day in month using Android Java?

Where the day today is

Oct 24, 2011
.

but using this code

Calendar currentDate = Calendar.getInstance();
int d = currentDate.DAY_OF_MONTH;


gives me the date
5


P.S. the date in emulator settings is
October 24, 2011

Answer
 currentDate.DAY_OF_MONTH; 

is constant which is used internally in Calendar class. To get the current day of month use

use

currentDate.get(Calendar.DAY_OF_MONTH);

Update:

how to shift the current date 6 days, and get the new day and month value ? //adding 6 days currentDate.add(Calendar.DATE, 6);

//retrieving the month now, note month starts from 0-Jan, 1-Feb
currentDate.get(Calendar.MONTH);