I have small code such as below. I expected that the result should be 7
, but it printed 6
. If I uncomment the line tmp.get(Calendar.MONTH)
, it runs OK (prints 7
).
Please let me know the reason. I'm using JDK 1.7.0_25 in MacOS.
public static void main(String[] args) {
Calendar tmp = Calendar.getInstance();
tmp.set(Calendar.DAY_OF_MONTH, 4);
tmp.set(Calendar.MONTH, Calendar.AUGUST);
//tmp.get(Calendar.MONTH);
tmp.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(tmp.get(Calendar.MONTH));
}
Screenshot:
Comment code: http://gyazo.com/4c099b1b2b90d72d1954b98b134e4ac3
Uncomment code: http://gyazo.com/fe368745da168646140ca9f3a60d2021