以简单日期格式解析月份的问题

Joh*_*rby 2 java date date-format simpledateformat

我得到的字符串有价值String val = "2012-08-01T12:00",并且我使用以下代码从中创建日历类型,问题是当我打印数据时,我得到的是07月而不是08,我怎样才能解决它来获得正确的月份?

1-7-2012-12-0-0

    SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
                    Date date = null;               
                    date = parserSDF.parse(Val);
                    Calendar cal = Calendar.getInstance();
                cal.setTime(date);

System.out.println(cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-"
                        + cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.HOUR_OF_DAY) + "-" + cal.get(Calendar.MINUTE)
                        + "-" + cal.get(Calendar.SECOND));
Run Code Online (Sandbox Code Playgroud)

mor*_*ano 5

你的问题在这里:

cal.get(Calendar.MONTH)
Run Code Online (Sandbox Code Playgroud)

1月= 0(不是 1),2月= 1(不是2)等