{"record":{"id":"dc26043e9e574d01","repo":"jeecgboot/JeecgBoot","slug":"could-not-parse-date-date-format-is-error","errorCode":null,"errorMessage":"Could not parse date, date format is error ","messagePattern":"Could not parse date, date format is error ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java","lineNumber":674,"sourceCode":"        return Long.valueOf(DateUtils.yyyymmddhhmmss.get().format(new Date()));\n    }\n\n    /**\n     * String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd\n     * HH:mm:ss“ * @param text String类型的时间值\n     */\n    @Override\n    public void setAsText(String text) throws IllegalArgumentException {\n        if (StringUtils.hasText(text)) {\n            try {\n                int length10 = 10;\n                int length19 = 19;\n                if (text.indexOf(SymbolConstant.COLON) == -1 && text.length() == length10) {\n                    setValue(DateUtils.date_sdf.get().parse(text));\n                } else if (text.indexOf(SymbolConstant.COLON) > 0 && text.length() == length19) {\n                    setValue(DateUtils.datetimeFormat.get().parse(text));\n                } else {\n                    throw new IllegalArgumentException(\"Could not parse date, date format is error \");\n                }\n            } catch (ParseException ex) {\n                IllegalArgumentException iae = new IllegalArgumentException(\"Could not parse date: \" + ex.getMessage());\n                iae.initCause(ex);\n                throw iae;\n            }\n        } else {\n            setValue(null);\n        }\n    }\n\n    public static int getYear() {\n        GregorianCalendar calendar = new GregorianCalendar();\n        calendar.setTime(getDate());\n        return calendar.get(Calendar.YEAR);\n    }\n\n    /**","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java#L656-L692","documentation":"This is a Spring PropertyEditor (setAsText) used to bind date strings. It accepts exactly two formats: a 10-char date without a colon (yyyy-MM-dd via date_sdf) and a 19-char datetime with a colon (yyyy-MM-dd HH:mm:ss via datetimeFormat). Any other length/format throws IllegalArgumentException with the literal message. A separate branch re-wraps actual ParseExceptions. This editor is registered for form binding and Excel import date columns.","triggerScenarios":"A date string bound via the property editor whose length is not 10 (no colon) or 19 (with colon) — e.g. '2024/01/01' (slashes, length 10, no colon but won't parse), '2024-1-1' (length 8), ISO with T ('2024-01-01T00:00:00', length 19 but separator is T not space so datetimeFormat parse fails -> throws the ParseException wrapper instead), or a time-only value.","commonSituations":"Excel import with mixed date formats; frontend sending ISO 8601 with 'T' separator or timezone offset; locale-specific date strings; a date picker returning 'yyyy/MM/dd'.","solutions":["Send dates in one of the two accepted formats: 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss'.","If you must accept other formats, register a custom PropertyEditor or use @DateTimeFormat(pattern=...) on the field.","Normalize date strings on the frontend before submission.","For Excel imports, ensure the cell format produces one of the two accepted string forms."],"exampleFix":"// before — client sends ISO with 'T'\n\"2024-01-01T12:00:00\" // length 19 but parse fails format-wise\n\n// after — use the space-separated datetime form\n\"2024-01-01 12:00:00\"","handlingStrategy":"validation","validationCode":"// Normalize date strings to the accepted formats before binding\npublic static String normalizeDate(String text) {\n  if (text == null || text.isBlank()) return null;\n  text = text.replace('T', ' ');\n  if (text.length() == 10) return text; // yyyy-MM-dd\n  if (text.length() >= 19) return text.substring(0, 19); // yyyy-MM-dd HH:mm:ss\n  throw new IllegalArgumentException(\"Unsupported date format: \" + text);\n}","typeGuard":"public static boolean isAcceptableDateFormat(String text) {\n  return text != null &&\n    ((text.length() == 10 && !text.contains(\":\")) ||\n     (text.length() == 19 && text.indexOf(':') > 0));\n}","tryCatchPattern":"try {\n  binder.setAutoGrowNestedPaths(true);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Could not parse date\")) {\n    // retry with normalized format or reject input\n  }\n}","preventionTips":["Standardize on 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss' for date bindings.","Use @DateTimeFormat on entity fields for non-standard formats.","Normalize date strings on the frontend before submission."],"tags":["backend","date-parsing","spring","property-editor","jeecg"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}