How to parse date with optional characters in format

后端 未结 3 1914
离开以前
离开以前 2020-12-12 02:20

I have the following two dates:

  • 8 Oct. 2009
  • 13 May 2010

I am using Jackson to convert the date from an rest api to joda Datetime.

3条回答
  •  渐次进展
    2020-12-12 03:14

    There would also be a different way by fixing the string for parsing:

    String date = "13 May. 2009";
    DateTime result = DateTime.parse(date.replace(".",""),
    DateTimeFormat.forPattern("dd MMM yyyy"));
    

提交回复
热议问题