Month is not printed from a date - Java DateFormat

前端 未结 7 1213
滥情空心
滥情空心 2020-12-02 00:18

How to get month from a date in java :

        DateFormat inputDF  = new SimpleDateFormat(\"mm/dd/yy\");
        Date date1 = inputDF.parse(\"9/30/11\");

          


        
7条回答
  •  情深已故
    2020-12-02 00:42

    mmis for minutes, use MM while specifying format.

    Calendar cal = Calendar.getInstance();
    cal.setTime(date1);
    
    int month = cal.get(Calendar.MONTH);// returns month value index starts from 0
    

提交回复
热议问题