How to convert string “2011-11-29 12:34:25” to date in “dd-MM-yyyy” format in JAVA

前端 未结 6 850
死守一世寂寞
死守一世寂寞 2020-12-21 15:30

I am trying to convert date which is in string and got format of \"yyyy-MM-dd HH:mm:ss\" to \"dd-MM-yyyy\".

I have implmented following code but its giving : java.

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 16:18

    You need to parse the date, using another SimpleDateFormat

    SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = dateFormat2.parse(values);
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    String mydate = dateFormat.format(date);
    

提交回复
热议问题