private Map<String, Integer> initiallCountContainer(RecordSearchMdl recordSearchMdl) { String beginMonth = DateUtil.format(recordSearchMdl.getStarttime(),"yyyyMM"); String endMonth = DateUtil.format(recordSearchMdl.getEndtime(),"yyyyMM"); Map<String, Integer> contMap = new HashMap<>(); if(beginMonth.equals(endMonth)){ contMap.put(beginMonth,0); return contMap; }else{ Calendar beginCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); beginCalendar.setTime( recordSearchMdl.getStarttime()); endCalendar.setTime(recordSearchMdl.getEndtime()); Integer bmoth = beginCalendar.get(Calendar.MONTH); contMap.put(beginMonth,0); for (int i = 1; i <6 ; i++) { //获取下个月压缩到map内; beginCalendar.add(Calendar.MONTH,+1); int nextMonthInt = beginCalendar.get(Calendar.MONTH); if(nextMonthInt==0){ nextMonthInt= 12; }else{ nextMonthInt = nextMonthInt+1; } String nextMonth = String.valueOf(nextMonthInt); if(nextMonth.length()<2) { nextMonth = "0"+(nextMonth); } String nextYm = String.valueOf(beginCalendar.get(Calendar.YEAR))+ nextMonth ; contMap.put(nextYm,0); //如果与结束月相同则停止初始化 int nextyearInt = beginCalendar.get(Calendar.YEAR); int endyearInt = endCalendar.get(Calendar.YEAR); int endMonthInt = endCalendar.get(Calendar.MONTH); if(nextyearInt == endyearInt && nextMonthInt == endMonthInt+1){ break; } } } return contMap; }
map 获取联系几个月,参数提供开始时间,和结束时间
最新推荐文章于 2023-04-25 15:39:16 发布