How to format Joda-Time DateTime to only mm/dd/yyyy?

前端 未结 9 1252
挽巷
挽巷 2020-11-29 15:52

I have a string \"11/15/2013 08:00:00\", I want to format it to \"11/15/2013\", what is the correct DateTimeFormatter pattern?

9条回答
  •  心在旅途
    2020-11-29 16:03

    I think this will work, if you are using JodaTime:

    String strDateTime = "11/15/2013 08:00:00";
    DateTime dateTime = DateTime.parse(strDateTime);
    DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd/YYYY");
    String strDateOnly = fmt.print(dateTime);
    

    I got part of this from here.

提交回复
热议问题