使用Joda Time时,应使用
DateTimeFormatter:
final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MMM-dd");final LocalDate dt = dtf.parseLocalDate(yourinput);如果使用Java 8或更高版本,请参考hertzi的答案
java.time
从Java 1.8开始,您可以使用java.time类而无需额外的库来实现此目的。请参阅教程。
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd");formatter = formatter.withLocale( putAppropriateLocaleHere ); // Locale specifies human language for translating, and cultural norms for lowercase/uppercase and abbreviations and such. Example: Locale.US or Locale.CANADA_FRENCHLocalDate date = LocalDate.parse("2005-nov-12", formatter);


