diff --git a/src/main/java/com/mobile_education_platform/util/DateUtil.java b/src/main/java/com/mobile_education_platform/util/DateUtil.java index 56087d6df86c4f1e2fbf660bbc0b2fe7913d21e5..9667bdb42144bc51e99d2621ba714a77689918a1 100644 --- a/src/main/java/com/mobile_education_platform/util/DateUtil.java +++ b/src/main/java/com/mobile_education_platform/util/DateUtil.java @@ -4,6 +4,7 @@ import org.springframework.stereotype.Component; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; /** @@ -33,4 +34,42 @@ public class DateUtil { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); return dateFormat.format(date); } + + /** + * @Description: 根据系统时间和学期,判断当前学年 + * @param + * @return schoolYear 学年 + * @Author: 陈斯然 + * @Date: 2021/10/27 18:50 + **/ + public static String getSchoolYear(){ + + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + + // 如果为第一学期,学年为[今年-今年+1],若为第二学期,学年为[今年-1-今年] + if ("1".equals(getSchoolSemester())){ + return String.valueOf(year) + "-" +String.valueOf(year+1); + } + return String.valueOf(year-1) + "-" +String.valueOf(year); + } + + /** + * @Description: 根据系统时间,判断当前学期 + * @param + * @return schoolSemester 学期 + * @Author: 陈斯然 + * @Date: 2021/10/27 18:51 + **/ + public static String getSchoolSemester(){ + + Calendar calendar = Calendar.getInstance(); + int month = calendar.get(Calendar.MONTH)+1; + + // 若为[8.9.10.11.12.1]则为第一学期,[2.3.4.5.6.7]为第二学期 + if ((month >=8 && month<=12) || month == 1){ + return "1"; + } + return "2"; + } }