Commit 18dbe93d authored by wujipeng's avatar wujipeng
Browse files

优化

parent 3b1e1453
......@@ -117,7 +117,7 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
}
List<ExamStudentVO> examStudentChildList = Lists.newArrayList();
for (ExamStudentVO examStudentVO : examStudentList) {
if (isSameDayWithFormat(examStudentVO.getExamTime().split("-")[0], date)) {
if (isSameDayWithFormat(examStudentVO.getExamTime(), date)) {
examStudentChildList.add(examStudentVO);
}
}
......@@ -239,7 +239,7 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
}
List<ExamStudentVO> examStudentChildList = Lists.newArrayList();
for (ExamStudentVO examStudentVO : examStudentList) {
if (isSameDayWithFormat(examStudentVO.getExamTime().split("-")[0], date)) {
if (isSameDayWithFormat(examStudentVO.getExamTime(), date)) {
examStudentChildList.add(examStudentVO);
}
}
......@@ -310,20 +310,13 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
* 方法2: 使用SimpleDateFormat格式化比较
* 将日期格式化为"yyyyMMdd"后比较字符串
*
* @param dateStr 日期字符串,格式:yyyy.MM.dd HH:mm:ss
* @param compareDate 要比较的Date对象
* @param date1 第一个Date对象
* @param date2 第二个Date对象
* @return 是否为同一天
*/
public static boolean isSameDayWithFormat(String dateStr, Date compareDate) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
Date inputDate = sdf.parse(dateStr);
public static boolean isSameDayWithFormat(Date date1, Date date2) {
SimpleDateFormat dayFormat = new SimpleDateFormat("yyyyMMdd");
return dayFormat.format(inputDate).equals(dayFormat.format(compareDate));
} catch (ParseException e) {
throw new IllegalArgumentException("日期格式错误,应为: yyyy.MM.dd HH:mm:ss", e);
}
return dayFormat.format(date1).equals(dayFormat.format(date2));
}
/**
......
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