gpt4 book ai didi

java - 日期解析不会因格式无效而失败

转载 作者:行者123 更新时间:2023-11-30 02:46:44 26 4
gpt4 key购买 nike

根据我的理解,下面的代码应该抛出解析异常,但事实并非如此。查看了文档但无法弄清楚。

DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd", Locale.US);
dateFormat.setLenient(false);
dateFormat.parse("20160821_$folder$");

最佳答案

这就是javadoc说:

Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.

只要找到匹配项,它就会停止进一步扫描,这里的情况似乎就是这样。

如果您想要严格检查,可以在此基础上添加 RegEx 数学,以防止解析此类字符串。

关于java - 日期解析不会因格式无效而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40022110/

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