Can anyone please help me understand why I am getting different month values for
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateFormat.format(cal.getTime())
+ "--"
+ cal.get(Calendar.MONTH));
Surprisingly displays
09/09/2012--8
In
Calendarclass,MONTHstart from index0. So,Januaryis 0,Februaryis 1, and henceSeptemberis 8.P.S.: – That’s true that this is an
InconsistencyinCalendarclass, so I would suggest you to take a look atJoda-Time APIto make your life easier while working with date-time data.