gpt4 book ai didi

java - ParseException 从未抛出

转载 作者:行者123 更新时间:2023-12-02 09:02:47 24 4
gpt4 key购买 nike

我有一个@Service带注释的服务类方法createShiftPlan(int numberOfEmployees, int startingMonth, int year)我在其中使用 SimpleDateFormat类(class)parse()方法。

如何在此处测试整数输入的解析异常?

最佳答案

设置SimpleDateFormat.setLenient(false)disable lenient parsing并提供一个不存在的日期,例如4 月 35 日。禁用 lenient 后,这将抛出 ParseException,而不是默默地修复日期。

关于java - ParseException 从未抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60039992/

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