map 获取联系几个月,参数提供开始时间,和结束时间

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小道士写程序

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值