gpt4 book ai didi

java-8 - 使用 STRICT 解析器样式时出现 DateTimeParseException 问题

转载 作者:行者123 更新时间:2023-12-01 15:52:01 27 4
gpt4 key购买 nike

我正在尝试使用以下模式解析日期字符串:yyMMddSTRICT解析器如下:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat).withResolverStyle(ResolverStyle.STRICT);
LocalDate.parse(expiryDate, formatter);

我得到以下 DateTimeParseException :

java.time.format.DateTimeParseException: Text '160501' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {YearOfEra=2016, MonthOfYear=5, DayOfMonth=1},ISO of type java.time.format.Parsed



当我切换到默认的解析样式时,即 ResolverStyle.SMART它允许诸如 2 月 30 日这样的日期。

有人可以帮忙吗?

最佳答案

严格解析器需要与 YearOfEra 一起使用的时代。更改您的模式以使用“u”而不是“y”,它会起作用,即。 “uuMMdd”。

关于java-8 - 使用 STRICT 解析器样式时出现 DateTimeParseException 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41103603/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com