This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You shouldn't rely on the exact return value. Instead, you should compare it with the constants provided with the Calendar class such as Calendar.JANUARY and Calendar.DECEMBER. Look at the appropriate Java API documentation for the version you are using.
If you need to store a month value internally as 1..12, then you should first calculate the offset from the start of your range to that returned by Calendar. Then you can add that to any value calculated using Calendar.That way you don't depend on any knowledge of Calendar.JANUARY other than that it is the first month, and I think that's a pretty safe assumption for the next few years at least.
The fact that Calendar.JANUARY == 0 is explicitly guaranteed in the Calendar API, and has been since the beginning. See Calendar.MONTH. It's not going to change. (This, unfortunately is why Sun can never correct the icky choices they made in making the month field start at 0 while the day of month field starts at 1.) So go ahead, Jack - add 1, you'll get the value you expect.
"I'm not back." - Bill Harding, Twister
Joined: Dec 29, 2004
Thank you. If it's 0 then addnig 1 will do for me.