|
|
@@ -23,7 +23,9 @@ import java.io.IOException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Configuration
|
|
|
@@ -90,16 +92,29 @@ public class JacksonConfig implements WebMvcConfigurer {
|
|
|
return null;
|
|
|
}
|
|
|
text = text.trim();
|
|
|
+
|
|
|
+ // 1. 尝试解析 ISO 8601 格式: 2026-04-09T16:00:00.000Z
|
|
|
+ try {
|
|
|
+ ZonedDateTime zonedDateTime = ZonedDateTime.parse(text);
|
|
|
+ return zonedDateTime.toLocalDateTime();
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
+ // 不是 ISO 8601 格式,继续尝试其他格式
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 尝试解析标准格式: yyyy-MM-dd HH:mm:ss
|
|
|
try {
|
|
|
return LocalDateTime.parse(text, DATE_TIME_FORMATTER);
|
|
|
} catch (Exception e) {
|
|
|
- try {
|
|
|
- String padded = text.length() == 16 ? text + ":00" : text;
|
|
|
- return LocalDateTime.parse(padded, DATE_TIME_FORMATTER);
|
|
|
- } catch (Exception ex) {
|
|
|
- throw new IOException(
|
|
|
- "无法解析日期时间: " + text + ", 支持格式: yyyy-MM-dd HH:mm:ss", ex);
|
|
|
- }
|
|
|
+ // 继续尝试其他格式
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 尝试解析缺少秒的格式: yyyy-MM-dd HH:mm
|
|
|
+ try {
|
|
|
+ String padded = text.length() == 16 ? text + ":00" : text;
|
|
|
+ return LocalDateTime.parse(padded, DATE_TIME_FORMATTER);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new IOException(
|
|
|
+ "无法解析日期时间: " + text + ", 支持格式: yyyy-MM-dd HH:mm:ss 或 ISO 8601", ex);
|
|
|
}
|
|
|
}
|
|
|
}
|