Parsing a year String to a LocalDate with Java8
问题 With Joda library, you can do DateTimeFormat.forPattern("yyyy").parseLocalDate("2008") that creates a LocalDate at Jan 1st, 2008 With Java8, you can try to do LocalDate.parse("2008",DateTimeFormatter.ofPattern("yyyy")) but that fails to parse: Text '2008' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {Year=2008},ISO of type java.time.format.Parsed Is there any alternative, instead of specifically writing sth like LocalDate.ofYearDay(Integer.valueOf("2008"), 1) ? 回答1: