根据年月获取这一月的日期

 

public static void main(String[] args) {
  List list = getMap();
  if (list.size() > 0) {
    for (int i = 0; i < list.size(); i++) {
      System.out.println(list.get(i));
    }
  }
}

public static List<String> getMap() {
  Map<Object, String> map = new LinkedHashMap<>();
  List list = getDayByMonth(2021, 8);
  if (list.size() > 0) {
    for (int i = 0; i < list.size(); i++) {
      // System.out.println(list.get(i));
      map.put(list.get(i), "白班");
    }
  }
  List list1 = new ArrayList();
  list1.add(0, map);
  return list1;
}

public static List<String> getDayByMonth(int yearParam, int monthParam) {
  List list = new ArrayList();
  Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
  aCalendar.set(yearParam, monthParam, 1);
  int year = aCalendar.get(Calendar.YEAR);//年份
  int month = aCalendar.get(Calendar.MONTH) + 1;//月份
  int day = aCalendar.getActualMaximum(Calendar.DATE);
  for (int i = 1; i <= day; i++) {
    String aDate = null;
    if (month < 10 && i < 10) {
      aDate = String.valueOf(year) + "-0" + month + "-0" + i;
    }
    if (month < 10 && i >= 10) {
      aDate = String.valueOf(year) + "-0" + month + "-" + i;
    }
    if (month >= 10 && i < 10) {
      aDate = String.valueOf(year) + "-" + month + "-0" + i;
    }
    if (month >= 10 && i >= 10) {
      aDate = String.valueOf(year) + "-" + month + "-" + i;
    }
    list.add(aDate);
  }
  return list;
}

上一篇:第一次上机考试总结


下一篇:Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题