How to convert Joda LocalDate to String in Java?

前端 未结 3 1171
刺人心
刺人心 2020-12-25 12:01

I got the answer: It\'s very simple.

DateTimeFormatter fmt = DateTimeFormat.forPattern(\"MM/dd/yyyy\");
String formattedDate = jodeLocalDateObj.toString( fmt         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 12:19

    LocalDate's toString can take a format string directly, so you can skip creating the DateTimeFormatter:

    String formattedDate = myLocalDate.toString("MM/dd/yyyy");
    

    https://www.joda.org/joda-time/apidocs/org/joda/time/LocalDate.html#toString-java.lang.String-

提交回复
热议问题