Month is not printed from a date - Java DateFormat
问题 How to get month from a date in java : DateFormat inputDF = new SimpleDateFormat("mm/dd/yy"); Date date1 = inputDF.parse("9/30/11"); Calendar cal = Calendar.getInstance(); cal.setTime(date1); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int year = cal.get(Calendar.YEAR); System.out.println(month+" - "+day+" - "+year); This code return day and year but not month. output : 0 - 30 - 2011 回答1: This is because your format is incorrect: you need "MM/dd/yy" for the