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

前端 未结 9 1238
挽巷
挽巷 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 15:57

    I am adding this here even though the other answers are completely acceptable. JodaTime has parsers pre built in DateTimeFormat:

    dateTime.toString(DateTimeFormat.longDate());
    

    This is most of the options printed out with their format:

    shortDate:         11/3/16
    shortDateTime:     11/3/16 4:25 AM
    mediumDate:        Nov 3, 2016
    mediumDateTime:    Nov 3, 2016 4:25:35 AM
    longDate:          November 3, 2016
    longDateTime:      November 3, 2016 4:25:35 AM MDT
    fullDate:          Thursday, November 3, 2016
    fullDateTime:      Thursday, November 3, 2016 4:25:35 AM Mountain Daylight Time
    

提交回复
热议问题