取消固定日期

parent 5942f615
......@@ -1184,13 +1184,23 @@ public class ChromosomeDataService {
// 处理带Z后缀的格式,将其转换为带+00:00时区的格式
dateString = dateString.substring(0, dateString.length() - 1) + "+00:00";
parsedDateTime = OffsetDateTime.parse(dateString).toLocalDateTime();
} else if (dateString.contains(" ")) {
// 处理包含空格的日期时间格式,如 "2026-01-07 00:00:00"
DateTimeFormatter spaceFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
parsedDateTime = LocalDateTime.parse(dateString, spaceFormatter);
} else {
// 尝试解析为OffsetDateTime然后转换为LocalDateTime
try {
parsedDateTime = OffsetDateTime.parse(dateString).toLocalDateTime();
} catch (DateTimeParseException e) {
// 如果不是偏移格式,尝试直接解析为LocalDateTime
parsedDateTime = LocalDateTime.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
try {
parsedDateTime = LocalDateTime.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
} catch (DateTimeParseException ex) {
// 最后尝试使用 "yyyy-MM-dd HH:mm:ss" 格式
DateTimeFormatter fallbackFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
parsedDateTime = LocalDateTime.parse(dateString, fallbackFormatter);
}
}
}
field.set(obj, parsedDateTime);
......@@ -1198,7 +1208,16 @@ public class ChromosomeDataService {
field.set(obj, (LocalDateTime) fieldValue);
} else {
// 尝试将其他类型转换为字符串再解析
field.set(obj, LocalDateTime.parse(fieldValue.toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
String dateString = fieldValue.toString();
// 同样处理各种格式
LocalDateTime parsedDateTime;
if (dateString.contains(" ")) {
DateTimeFormatter spaceFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
parsedDateTime = LocalDateTime.parse(dateString, spaceFormatter);
} else {
parsedDateTime = LocalDateTime.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
}
field.set(obj, parsedDateTime);
}
} else {
field.set(obj, fieldValue);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment