Month is not printed from a date - Java DateFormat

前端 未结 7 1215
滥情空心
滥情空心 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:53

    If you read the SimpleDateFormat javadoc, you'll notice that mm is for minutes. You need MM for month.

    DateFormat inputDF  = new SimpleDateFormat("MM/dd/yy");
    

    Otherwise the format doesn't read a month field and assumes a value of 0.

提交回复
热议问题