Calendar cl = Calendar.getInstance(); int nowMonth = cl.get(Calendar.MONTH); // 0 int nowMonth2 = cl.get(Calendar.MONTH - 1); // 2017? 

In January, nowMonth is 0 , good.
Why nowMonth2 - 2017 ? Those. returns year.

  • int nowMonth2 = cl.get (Calendar.MONTH) - 1; - pavlofff

1 answer 1

Because the Calendar.MONTH constant is 2 , and Calendar.YEAR is 1 .
The .get() method returns the value of the corresponding field. Therefore, if you pass 1 (and Calendar.MONTH - 1 is 2 - 1 = 1) , then you get a year.