栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

具有父级且没有分隔符的DateTimeFormatter模式不起作用

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

具有父级且没有分隔符的DateTimeFormatter模式不起作用

中有一个错误
DateTimePrinterParser

我逐步调试了整个过程,显然您不能将数字用作文字。如果从头到尾调试所有方法,则类似的测试代码也可以证明这一点

DateTimeFormatterBuilder.parse()

显然,如果

Value(YearOfEra,4,19,EXCEEDS_PAD)
解析器 不是*
数字,则解析器将消耗
00
它们停在的位置,因为解析器正在寻找数字到数字的长度。该嵌入的是错误的。


*
4``19``DateTimeFormatter``DateTimeParseContext

如果您像使用非数字字符文字一样使用

xx
它,那么数字文字则不会。

这两个均失败:

final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM'00'");System.out.println(sdf.parse("20150100"));

线程“主”中的异常java.text.ParseException:无法解析的日期:java.text.DateFormat.parse(DateFormat.java:366)处的“
20150100”

final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMM'00'");System.out.println(dateTimeFormatter.parse("20150100", YearMonth::from));

线程“主”中的异常java.time.format.DateTimeParseException:无法在java.time.format.DateTimeFormatter的java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)的索引0处解析文本“
20150100” .parse(DateTimeFormatter.java:1851)

这些都成功:

final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM'xx'");System.out.println(sdf.parse("201501xx"));

美国东部时间2015年1月1日星期四00:00:00

final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMM'xx'");System.out.println(dateTimeFormatter.parse("201501xx", YearMonth::from));

2015-01



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/506382.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号