java.lang.IllegalArgumentException: 无效格式: "2018-08-24T��:��:��" 在 "��:��:��" 处格式不正确



前端正在发送具有无效时间格式的日期,我收到此异常:

原因:java.lang.IllegalArgumentException: 格式无效: "2018-08-24T : : " 在 " : : " 处格式不正确 org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187( 在 org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:826( 在 org.joda.time.convert.StringConverter.getInstantMillis(StringConverter.java:65( at org.joda.time.base.BaseDateTime.(基准日期时间.java:173( 在org.joda.time.DateTime。(日期时间.java:257(

基本上我想检查时间戳是否有任何格式不正确的数据。如果是,我想将其设置为 0。例如,日期时间是2018-08-24T��:��:��我想将其设置为2018-08-24T00:00:00

你已经走到了一半。

try {
.. your code that parses the FED input
} catch ( IllegalArgumentException e) {
.. do further checking

意思是:当你从源收到错误的输入时,这个异常已经给你一个例外。在这种情况下,您可以简单地对传入字符串进行 substring(( 或正则表达式检查。如果它变成"4 位数字破折号 2 位数字破折号 2 位数字"......然后你得到了一个日期,可以手动创建一个相应的对象,并将时间值填写到所有

0。

最新更新