我知道一年中的周数,一周从星期日开始,然后是星期一,星期二......星期六.
既然我知道周数,那么通过使用Java代码获取特定周的日期的有效方法是什么?
我要解析的字符串类型:“ 36/2017”,其中36个是一年中的第一个星期,2017年是该年。
我的代码:
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendPattern("w/uuuu")
.parseDefaulting(ChronoField.DAY_OF_WEEK, 1)
.toFormatter();
LocalDate date = LocalDate.parse("36/2017", formatter);
Run Code Online (Sandbox Code Playgroud)
我添加了默认日期。
我收到此消息:
java.time.format.DateTimeParseException: Text '36/2017' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {WeekOfWeekBasedYear[WeekFields[MONDAY,4]]=36, Year=2017, DayOfWeek=1},ISO of type java.time.format.Parsed
Run Code Online (Sandbox Code Playgroud)
任何的想法 ?谢谢 !