jeecgboot/JeecgBoot · error · IllegalArgumentException
Could not parse date, date format is error
Error message
Could not parse date, date format is error
What it means
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.
Source
Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java:674
return Long.valueOf(DateUtils.yyyymmddhhmmss.get().format(new Date()));
}
/**
* String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd
* HH:mm:ss“ * @param text String类型的时间值
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (StringUtils.hasText(text)) {
try {
int length10 = 10;
int length19 = 19;
if (text.indexOf(SymbolConstant.COLON) == -1 && text.length() == length10) {
setValue(DateUtils.date_sdf.get().parse(text));
} else if (text.indexOf(SymbolConstant.COLON) > 0 && text.length() == length19) {
setValue(DateUtils.datetimeFormat.get().parse(text));
} else {
throw new IllegalArgumentException("Could not parse date, date format is error ");
}
} catch (ParseException ex) {
IllegalArgumentException iae = new IllegalArgumentException("Could not parse date: " + ex.getMessage());
iae.initCause(ex);
throw iae;
}
} else {
setValue(null);
}
}
public static int getYear() {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(getDate());
return calendar.get(Calendar.YEAR);
}
/**View on GitHub (pinned to 96fb33f5ec)
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.
Example fix
// before — client sends ISO with 'T' "2024-01-01T12:00:00" // length 19 but parse fails format-wise // after — use the space-separated datetime form "2024-01-01 12:00:00"
Defensive patterns
Strategy: validation
Validate before calling
// Normalize date strings to the accepted formats before binding
public static String normalizeDate(String text) {
if (text == null || text.isBlank()) return null;
text = text.replace('T', ' ');
if (text.length() == 10) return text; // yyyy-MM-dd
if (text.length() >= 19) return text.substring(0, 19); // yyyy-MM-dd HH:mm:ss
throw new IllegalArgumentException("Unsupported date format: " + text);
} Type guard
public static boolean isAcceptableDateFormat(String text) {
return text != null &&
((text.length() == 10 && !text.contains(":")) ||
(text.length() == 19 && text.indexOf(':') > 0));
} Try / catch
try {
binder.setAutoGrowNestedPaths(true);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Could not parse date")) {
// retry with normalized format or reject input
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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'.
Related errors
- 请注意,将要排序的列字段不存在:${column}
- 未获取到用户
- Illegal access to path outside of base directory.
- 非法业务路径,禁止访问上传目录之外的路径: ${bizPath}
- 模板缺少参数:${item}
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/dc26043e9e574d01.
Report an issue: GitHub.