其他分享
首页 > 其他分享> > 根据年月获取这一月的日期

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

作者:互联网

 

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;
}

标签:10,String,int,List,一月,list,month,获取,日期
来源: https://www.cnblogs.com/w852894903/p/15697043.html