java.util.date to String using DateTimeFormatter

前端 未结 5 2065
抹茶落季
抹茶落季 2021-02-12 12:08

How can I convert a java.util.Date to String using

 DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(\"yyyy-MM-dd\'T\'H         


        
5条回答
  •  情歌与酒
    2021-02-12 13:03

    since I asume you are using joda API: ergo, DateTimeFormatter is comming from org.joda.time.format.DateTimeFormatter:

     String dateTime = "02-13-2017 18:20:30";
    // Format for input
    DateTimeFormatter dtf = DateTimeFormat.forPattern("MM-dd-yyyy HH:mm:ss");
    // Parsing the date
    DateTime jodatime = dtf.parseDateTime(dateTime);
    
    System.out.println(jodatime );
    

提交回复
热议问题