I've a datetime
with value
"Mon Jan 12 06:20:06 IST 1976"
How can I extract just the date from it?
12 Jan 1976
Thank you!
I've a datetime
with value
"Mon Jan 12 06:20:06 IST 1976"
How can I extract just the date from it?
12 Jan 1976
Thank you!
Using DateTimeFormatter in Java 8, you can easily do the parsing.
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"));
And you can generate String
objects, automatically localized.
DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
DateTimeFormatter timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
String date = dateFormatter.format(localDateTime.toLocalDate());
String time = timeFormatter.format(localDateTime.toLocalTime());
Jan 12, 1976
6:20:06 AM