How to get a Date object from String

前端 未结 5 1325
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 06:03
DateFormat formatter = new SimpleDateFormat(\"MM/dd/yyyy\' \'HH:mm:ss\");
Date d = (Date)formatter.parse(dateTime);
System.out.println(\"date in controller \"+d);
         


        
5条回答
  •  野的像风
    2021-01-13 06:45

    Try using format instead of parse.

    Date date = new Date();
    String DATE_FORMAT = "MM/dd/yyyy";      
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);        
    System.out.println("Today is " + sdf.format(date) );
    

提交回复
热议问题