我有以下代码:-
Calendar calc = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("MMM-yyyy");
calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
calc.set(Calendar.MONTH, Calendar.NOVEMBER);
System.out.println("---NOV? : " + sdf.format(calc.getTime()));
Calendar calc1 = Calendar.getInstance();
calc1.set(Calendar.YEAR, calc1.get(Calendar.YEAR) - 1);
calc1.set(Calendar.MONTH, Calendar.DECEMBER);
System.out.println("-- DEC : " + sdf.format(calc1.getTime()));
上述代码的输出是:-
> ---NOV? : Dec-2012
> -- DEC : Dec-2012
这只发生在 1 月 31 日,有人可以解释为什么会发生这种情况吗?