将日期转换为日历问题

sol*_*lid 2 java calendar date

今天是2013-02-25,但为什么这段代码会返回2013-03-25?

       String currentDate =  new SimpleDateFormat("yyyy MM dd hh mm ss").format(new java.util.Date());
       System.out.println("current Date "+currentDate);
       StringTokenizer  token = new StringTokenizer(currentDate);
       Calendar cal = Calendar.getInstance();
       cal.set(Integer.parseInt(token.nextToken()),
               Integer.parseInt(token.nextToken()), 
               Integer.parseInt(token.nextToken()), 
               Integer.parseInt(token.nextToken()),
               Integer.parseInt(token.nextToken()),
               Integer.parseInt(token.nextToken()));
       String calenderDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(cal.getTime());
       System.out.println("calender date "+calenderDate);
       cal.add(Calendar.MONTH, -1); //  set to one month ago
       String pastDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(cal.getTime());
       System.out.println("past Date "+pastDate);
Run Code Online (Sandbox Code Playgroud)

出去

当前日期2013 02 25 04 56 26

日历日期2013-03-25 04:56:26

过去日期2013-02-25 04:56:26

Alb*_*ura 5

减去一个月.所以它适用于API.即:

month - 用于设置MONTH日历字段的值.月值基于0.例如,1月份为0.