我有以下代码。获取月份时会出现问题。它说“‘月’参数必须在 1 到 12 的范围内。” 它总是返回 0。为什么?
String target = "2013-01-04";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = df.parse(target);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
System.out.println("year-"+year);
int month = cal.get(Calendar.MONTH);
System.out.println("month-"+month);
int day = cal.get(Calendar.DAY_OF_MONTH);
System.out.println("day-"+day);