clankill3r clankill3r - 3 months ago 9
Java Question

String to LocalDate

How can i convert a string to a

LocalDate
?

I have seen examples like:

LocalDate dt = new LocalDate("2005-11-12");


But my strings are like:

2005-nov-12

fge fge
Answer

As you use Joda Time, you should use DateTimeFormatter:

final DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MMM-dd");
final LocalDate dt = dtf.parseLocalDate(yourinput);

If using Java 8 or later, then refer to hertzi's answer