前端正在发送具有无效时间格式的日期,我收到此异常:
Caused by: java.lang.IllegalArgumentException: Invalid format: "2018-08-24T��:��:��" is malformed at "��:��:��" at org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187) at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:826) at org.joda.time.convert.StringConverter.getInstantMillis(StringConverter.java:65) at org.joda.time.base.BaseDateTime.(BaseDateTime.java:173) at org.joda.time.DateTime.(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。
关于java.lang.IllegalArgumentException : Invalid format: "2018-08-24T��:��:��" is malformed at "��:��:��",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52003881/