根据两个学年学期获取之间所有的,前闭后闭
-
学年学期格式
例:2020-2021-1、2020-2021-2
ps:每个学年学期,第1个学年比第2个学年小1,最后一位的1和2代表学期。
-
实现代码
public static Set<String> getAllXnxq(String beginXnxq, String endXnxq) { Set<String> AllXnxqSet = new LinkedHashSet<>(); String[] bs = beginXnxq.split("-"); String[] es = endXnxq.split("-"); int bs0 = Integer.parseInt(bs[0]); int bs2 = Integer.parseInt(bs[2]); int es0 = Integer.parseInt(es[0]); int es2 = Integer.parseInt(es[2]); for (int i = 0; i <= es0 - bs0; i++) { int year = bs0 + i; if (year == bs0) { if (bs2 == 1) { AllXnxqSet.add(year + "-" + (year + 1) + "-" + "1"); } if (es0 > bs0 || es2 == 2) { AllXnxqSet.add(year + "-" + (year + 1) + "-" + "2"); } } else if (year > bs0 && year < es0) { AllXnxqSet.add(year + "-" + (year + 1) + "-" + "1"); AllXnxqSet.add(year + "-" + (year + 1) + "-" + "2"); } else if (year == es0) { AllXnxqSet.add(year + "-" + (year + 1) + "-" + "1"); if (es2 == 2) { AllXnxqSet.add(year + "-" + (year + 1) + "-" + "2"); } } } return AllXnxqSet; }
3.示例