I was playing with the Calendar class and got some confusing results:
Calendar thisCal = Calendar.getInstance();
thisCal.clear();
thisCal.set(2012,12,8);
System.out.println("Year is: " + thisCal.get(Calendar.YEAR));
System.out.println("Month is: " + thisCal.get(Calendar.MONTH));
System.out.println("Day of Month is: " + thisCal.get(Calendar.DAY_OF_MONTH));
The output:
Year is: 2013
Month is: 0
Day of Month is: 8
Confused I am!
The
MONTHfield is zero based (inherited from some POSIX API, I think). So you’re setting it to the 13th month of 2012, which it interprets as the first month (with number 0) of 2013.If you set the
lenientproperty tofalse, it would throw an Exception instead.