处理日期
This commit is contained in:
+23
-6
@@ -906,13 +906,30 @@ public class ShiftManageDomainService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date stringToDate(String dateStr) {
|
public Date stringToDate(String dateStr) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
if (dateStr == null || dateStr.trim().isEmpty()) {
|
||||||
try {
|
return null;
|
||||||
return sdf.parse(dateStr);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
|
// 去除首尾空格
|
||||||
|
dateStr = dateStr.trim();
|
||||||
|
// 定义可能的格式
|
||||||
|
String[] patterns = {
|
||||||
|
"yyyy-MM-dd HH:mm:ss", // 完整时间
|
||||||
|
"yyyy-MM-dd HH:mm", // 到分钟
|
||||||
|
"yyyy-MM-dd", // 只有日期 (报错的这个)
|
||||||
|
"yyyy/MM/dd HH:mm:ss",
|
||||||
|
"yyyy/MM/dd"
|
||||||
|
};
|
||||||
|
for (String pattern : patterns) {
|
||||||
|
try {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||||
|
// 设置严格解析,避免将 2026-03-0112:00:00 这种错误数据解析成功
|
||||||
|
sdf.setLenient(false);
|
||||||
|
return sdf.parse(dateStr);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("无法解析的日期格式: " + dateStr + ",支持格式:yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** PO 转 DO,含 children 递归转换 */
|
/** PO 转 DO,含 children 递归转换 */
|
||||||
|
|||||||
Reference in New Issue
Block a user