0

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.

Raghuveer
  • 2,859
  • 7
  • 34
  • 66

1 Answers1

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