Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar returns wrong month [duplicate]

Tags:

java

calendar

Calendar rightNow = Calendar.getInstance(); String month = String.valueOf(rightNow.get(Calendar.MONTH)); 

After the execution of the above snippet, month gets a value of 10 instead of 11. How come?

like image 429
Hant Avatar asked Nov 18 '09 10:11

Hant


1 Answers

Months are indexed from 0 not 1 so 10 is November and 11 will be December.

like image 195
Vincent Ramdhanie Avatar answered Sep 22 '22 07:09

Vincent Ramdhanie