From 16e2388a7cd7c5c7257252eb66b322486a78f1b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=96=AF=E7=84=B6?= <2286974448@qq.com> Date: Wed, 27 Oct 2021 18:59:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=B8=A4=E4=B8=AA=E9=9D=99?= =?UTF-8?q?=E6=80=81=E6=96=B9=E6=B3=95=EF=BC=8C=E7=94=A8=E4=BA=8E=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E5=AD=A6=E5=B9=B4+=E5=AD=A6?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/DateUtil.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) 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 56087d6..9667bdb 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"; + } } -- Gitee