Java date format

前端 未结 5 1322
余生分开走
余生分开走 2021-01-16 01:41

Have String str \"May 23 2011 12:20:00\", want to convert it to date such this:

Date date = (new SimpleDateFormat(\"MMM dd yyyy HH:mm:ss\")).parse(str);
         


        
5条回答
  •  悲&欢浪女
    2021-01-16 02:14

    You may need to additionally specify the Locale, when the default Locale of your VM is not an English one:

    Date date = (new SimpleDateFormat("MMM dd yyyy HH:mm:ss", Locale.US)).parse(str);
    

提交回复
热议问题