病人管理 格式化代码

This commit is contained in:
liuhongrui
2025-03-17 11:17:43 +08:00
parent cd04bca322
commit cc8a314f66
9 changed files with 265 additions and 197 deletions

View File

@@ -232,5 +232,50 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return null;
}
/**
* 判断日期是否为未来时间
*
* @param dateString 字符串日期
* @return 是/否
*/
public static boolean isFuture(String dateString) {
// 创建 DateTimeFormatter 对象,并设置所需的日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
try {
// 解析字符串为 LocalDate 对象
LocalDate dateToCheck = LocalDate.parse(dateString, formatter);
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 检查日期是否是未来的时间
return dateToCheck.isAfter(currentDate);
} catch (Exception e) {
e.printStackTrace();
// 解析失败或其他异常,返回 false 或根据需要处理异常
return false;
}
}
/**
* 从身份证号码中提取生日
*
* @param idCard 身份证号
* @return 出生日
*/
public static Date extractBirthday(String idCard) {
if (idCard == null) {
// 身份证号码为空
return null;
}
// 提取第7到14位作为生日字符串
String birthdayStr = idCard.substring(6, 14);
// 将生日字符串转换为 LocalDate
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate date = LocalDate.parse(birthdayStr, formatter);
// 将 LocalDate 转换为 java.util.Date
return Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
}