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

前端 未结 6 846
死守一世寂寞
死守一世寂寞 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:10

    The IllegalArgumentException probably occurs when program trying to construct Date object

    What's the value ?

    Following code snippet runs correctly.

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Date date = new Date();
    String mydate = dateFormat.format(date);
    
    System.out.println(mydate);
    

    Output :

    29/11/2011

提交回复
热议问题