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 回答1: As you use Joda Time, you should use DateTimeFormatter : final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MMM-dd"); final LocalDate dt = dtf.parseLocalDate(yourinput); If using Java 8 or later, then refer to hertzi's answer 回答2: java.time Since Java 1.8, you can achieve this without an extra library by using the java.time