up
This commit is contained in:
@@ -20,4 +20,12 @@ public interface IPatientService extends IService<Patient> {
|
||||
* @return 出生日
|
||||
*/
|
||||
Date extractBirthday(String idCard);
|
||||
|
||||
/**
|
||||
* 判断日期是否为未来时间
|
||||
*
|
||||
* @param date 字符串日期
|
||||
* @return 是/否
|
||||
*/
|
||||
boolean isFuture(String date);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> impl
|
||||
|
||||
/**
|
||||
* 从身份证号码中提取生日
|
||||
*
|
||||
*
|
||||
* @param idCard 身份证号
|
||||
* @return 出生日
|
||||
*/
|
||||
@@ -43,4 +43,23 @@ public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> impl
|
||||
return Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user