Today is June 30th, and you never set the day of the month in your code, so the 30th is assumed. Since February, less than 30 days, it overflows, and you finish in March. Try the code below and note that setting the day of the month affects the displayed text:
calendarTemp.set(Calendar.MONTH, 1);
calendarTemp.set(Calendar.DAY_OF_MONTH, 1);
As a note, this makes the code more readable for using constants from a class Calendar, for example. Calendar.FEBRUARYinstead of magic numbers, especially because months are based on 0 ...
source
share