ParseException when parsing 3 character abbreviated month using SimpleDateFormat

前端 未结 5 520
说谎
说谎 2020-12-22 14:56

Here is my code,

SimpleDateFormat format = new SimpleDateFormat(\"dd-MM-yyyy HH:mm:ss\");
Date dft  = (Date) format.parse(\"16-MAY-2018 09:30:22:000\");
         


        
5条回答
  •  失恋的感觉
    2020-12-22 15:44

    "16-MAY-2018 09:30:22" is not parsable with that time format. If you want to parse that you have to change date format to "dd-MMM-yyyy HH:mm:ss". The double M is only for numbered months (so should be 05 for May).

    Check the SimpleDateFormat javadoc for more details: here

提交回复
热议问题