androidcalendar

Calendar.MONTH gives wrong value


I'm trying to get the actual month from the Calendar using the following:

Calendar c = Calendar.getInstance();          
String time = String.valueOf(c.get(Calendar.MONTH));

According the system settings "Settings --> Date & Time" actual month is 10 while get(Calendar.MONTH) returns 09.


Solution

  • Keep in mind that months values start from 0, so October is actually month number 9.

    http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Calendar.html#MONTH