java.util.date/Calendar/SimpleDataFormat:在java中添加/增加月份

java.util.date/Calendar/SimpleDataFormat:在java中添加/增加月份,java,simpledateformat,Java,Simpledateformat,我试过以下方法;但结果令人失望。 我想增加几个月的工资 String dStartTime="2012-03-01"; SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-DD"); Date dateStartTime = dateFormatter.parse(dStartTime); Calendar cal = Calendar.getInstance(); cal.setTime(dateStartTi

我试过以下方法;但结果令人失望。
我想增加几个月的工资

 String dStartTime="2012-03-01";
 SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-DD");
 Date dateStartTime = dateFormatter.parse(dStartTime);
 Calendar cal = Calendar.getInstance();
 cal.setTime(dateStartTime); 
 cal.add(Calendar.MONTH, 1);
 System.out.println(cal.getTime());
 System.out.println(dateFormatter.format(cal.getTime())); 
输出
2012年2月1日星期三00:00:00——这是正确的
2012-02-32---这是错误的。我希望这一天应该是一天


请告诉我这里有什么问题

新简化格式(“yyyy-MM-DD”)
更改为
新简化格式(“yyyy-MM-DD”)
DD
是“年中的一天”,但您需要
DD
是“月中的一天”。
有关日期和时间模式,请参阅。

您可以在javadoc中找到所有有效的模式字符: