小编Flo*_*low的帖子

将具有星期和年份的字符串解析为LocalDate

我要解析的字符串类型:“ 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)

任何的想法 ?谢谢 !

java date java-time

3
推荐指数
1
解决办法
62
查看次数

标签 统计

date ×1

java ×1

java-time ×1