Trying to convert string date into a date

前端 未结 3 1949
有刺的猬
有刺的猬 2021-01-28 17:42

java.text.ParseException: Unparseable date: \"Sat May 01 00:00:00 EDT 2010\"

I am trying to parse this date using the SimpleDateFormat class.

java.util.         


        
3条回答
  •  遥遥无期
    2021-01-28 18:37

    DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy");
    Date date = (Date)formatter.parse("Sat May 01 00:00:00 EDT 2010");
    String string = new String(date.getYear() + "-" + date.getMonth() + "-" + date.getDay());
    

    Should work better then just yyyy-MM-dd.

提交回复
热议问题