【发布时间】:2017-05-12 12:02:40
【问题描述】:
有了 Joda 库,你可以做到
DateTimeFormat.forPattern("yyyy").parseLocalDate("2008")
在 2008 年 1 月 1 日创建 LocalDate
用Java8,你可以尝试做
LocalDate.parse("2008",DateTimeFormatter.ofPattern("yyyy"))
但解析失败:
Text '2008' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {Year=2008},ISO of type java.time.format.Parsed
有没有其他选择,而不是专门写某事
LocalDate.ofYearDay(Integer.valueOf("2008"), 1)
?
【问题讨论】:
-
自己写方法?