Search code examples
javacalendar

Java Calendar, getting current month value, clarification needed


On November 1st ..

  Calendar.getInstance().get(Calendar.MONTH); // prints 10 (October)

It would make sense if we start with 0, but it appears that we do not

  Calendar.getInstance().get(Calendar.JANUARY); // prints 1

What am i missing please?


Solution

  • Months in Java Calendar are 0-indexed. Calendar.JANUARY isn't a field so you shouldn't be passing it in to the get method.