Anybody know why the month that the Calendar class display is one month less than the current month? e.g. Calendar ca = Calendar.getInstance(); System.out.print( ca.get( Calendar.MONTH ) ); will display 6 instead of 7 (current month is July, it should be 7!) Thanks in advance!
I think it must be because of some historical reasons... Computers have always started counting from zero. The first index of an array is at 0 elements-offset, therefore at index 0. For months it is the same. When January starts, no months have occured before, so it is at 0 months-offset. That's why January is Zero. And December is Eleven! This is merely speculation, but after a while one gets used to counting months from 0 to 11, and it starts to feel really weird if one has to write code lines where it isn't that way.
Sun Certified Programmer for the Java 2 Platform 1.4<p>If I can create, I will make mistakes. If I can learn with them, it must be some kind of art.
1st thing: "Lilly"- Welcome to the JavaRanch! Please adjust your displayed name to match the JavaRanch Naming Policy. You can change it here. Thanks! and again welcome to the JavaRanch! 2nd thing: Check out this blip of code, the Calendar.MONTH is off by one.
[ July 12, 2002: Message edited by: Jessica Sant ]