Joda Time:如何将字符串转换为LocalDate?

24 浏览
0 Comments

Joda Time:如何将字符串转换为LocalDate?

如何指定格式字符串以将日期从字符串中转换出来。在我的情况下,只有日期部分是相关的。

将其构建为DateTime会失败:

String dateString = "2009-04-17";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime dateTime = formatter.parseDateTime(dateString);

出现错误:java.lang.IllegalArgumentException: Invalid format: "2011-04-17" is too short

可能是因为我应该使用LocalDate。但是,我没有看到任何LocalDate的格式化程序。将String dateString = "2009-04-17";转换为LocalDate(或其他适当的表示)的最佳方法是什么?

谢谢...

0