提取日期 "Mon Jan 12 06:20:06 IST 1976"



我有一个值为的datetime

"Mon Jan 12 06:20:06 IST 1976" 

如何从中提取日期?

12 Jan 1976

谢谢!

使用Java8中的DateTimeFormatter,您可以轻松地进行解析。

String s = "Mon Jan 12 06:20:06 IST 1976";
ZonedDateTime localDateTime = ZonedDateTime.parse(s, DateTimeFormatter.ofPattern("E MMM dd HH:mm:ss z yyyy"));

您可以生成String对象,并自动本地化。

DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
DateTimeFormatter timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
String date = dateFormatter.format(localDateTime.toLocalDate());
String time = timeFormatter.format(localDateTime.toLocalTime());

1976年1月12日

上午6:20:06

最新更新