【发布时间】:2016-04-14 11:43:03
【问题描述】:
我想解析像 2011-11-30 这样的日期字符串:
LocalDateTime.parse("2011-11-30", DateTimeFormatter.ISO_LOCAL_DATE)
但我得到以下异常:
java.time.format.DateTimeParseException: Text '2011-11-30' could not be parsed:
Unable to obtain LocalDateTime from TemporalAccessor
如果我传递一个日期 和时间字符串,一切都会按预期工作:
LocalDateTime.parse("2011-11-30T23:59:59", DateTimeFormatter.ISO_LOCAL_DATE_TIME)
如何将2011-11-30 之类的日期解析为 LocalDateTime(具有默认时间)?
【问题讨论】:
-
好吧,使用 LocalDate.parse(),然后通过指定您想要的时间将其更改为 LocalDateTime。
标签: java datetime java-time iso localdatetime