I have a date of the form "20th Oct 2017" how do I convert it to "2017-10-20". In specific I don't see the format for 20th
. I am able to get the format for month and year "MMM yyyy"
I would like to know the format for the day.
Asked
Active
Viewed 49 times
1 Answers
1
Try this one:
DateTimeFormatter parseFormatter = DateTimeFormatter.ofPattern("MMM d['st']['nd']['rd']['th'] uuuu h:mma", Locale.ENGLISH);
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, parseFormatter);
Considering Java 8 features, you can format your date in various ways. Just check the following formats and ways of parsing and formatting the date:
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

Andrea Calin
- 308
- 2
- 10
-
I have already seen it and cant find how to represent `20th` can you please point it ? – Raghuveer Nov 13 '18 at 13:42
-
try the edited code ... – Andrea Calin Nov 13 '18 at 14:20
-
https://stackoverflow.com/questions/28514346/parsing-a-date-s-ordinal-indicator-st-nd-rd-th-in-a-date-time-string says we do not have a format of that type. – Raghuveer Nov 13 '18 at 14:29