How to format Joda-Time DateTime to only mm/dd/yyy

2019-01-12 15:55发布

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?

I've tried many and googled and still unable to find the correct pattern.

edit: I am looking for Joda-Time DateTimeFormatter, not Java's SimpleDateFormat..

8条回答
戒情不戒烟
2楼-- · 2019-01-12 16:32

Another way of doing that is:

String date = dateAndTime.substring(0, dateAndTime.indexOf(" "));

I'm not exactly certain, but I think this might be faster/use less memory than using the .split() method.

查看更多
Bombasti
3楼-- · 2019-01-12 16:35

just want string:

 DateTime.parse("201711201515",DateTimeFormat.forPattern("yyyyMMddHHmm")).toString("yyyyMMdd");

if want datetime:

DateTime.parse("201711201515", DateTimeFormat.forPattern("yyyyMMddHHmm")).withTimeAtStartOfDay();
查看更多
登录 后发表回答