ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java-Calendar使用

2022-03-21 12:02:26  阅读:191  来源: 互联网

标签:java format simpleDateFormat 使用 new Calendar calendar sim


    /**
     * 累计使用 上月使用  本月使用 上周使用 本周使用 本月剩余
     * @param schoolId
     * @param currPage
     * @param pageSize
     * @return
     */
    @Override
    public PageBean<KwDevicePhoneSim> listSim(Integer schoolId, Integer currPage, Integer pageSize) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.set(Calendar.DAY_OF_WEEK, 2);
        String fromDateWeek = simpleDateFormat.format(calendar.getTime());
        calendar.add(Calendar.WEEK_OF_YEAR,-1);
        String fromDateLastWeek = simpleDateFormat.format(calendar.getTime());

        Calendar calendar2 = Calendar.getInstance();
        calendar2.setFirstDayOfWeek(Calendar.MONDAY);
        calendar2.set(Calendar.DAY_OF_WEEK, 1);
        String toDateWeek = simpleDateFormat.format(calendar2.getTime());
        calendar.add(Calendar.WEEK_OF_YEAR,-1);
        String toDateLastWeek = simpleDateFormat.format(calendar2.getTime());

        Calendar calendar3 = Calendar.getInstance();
        calendar3.setTime(new Date());
        calendar3.set(Calendar.DAY_OF_MONTH, 0);
        String toDateLastMoth = simpleDateFormat.format(calendar3.getTime());

        Calendar calendar4 = Calendar.getInstance();
        calendar4.setTime(new Date());
        calendar4.set(Calendar.DAY_OF_MONTH, 1);
        calendar4.add(Calendar.MONTH,-1);
        String fromDateLastMonth = simpleDateFormat.format(calendar4.getTime());

        //这个月的第一天
        Calendar calendar5 = Calendar.getInstance();
        calendar5.setTime(new Date());
        calendar5.set(Calendar.DAY_OF_MONTH, 1);
        String fromDateMonth = simpleDateFormat.format(calendar5.getTime());

        String toDateMonth = simpleDateFormat.format(new Date());

        PageHelper.startPage(currPage, pageSize);
        List<KwDevicePhoneSim> phoneSimList = baseMapper.selectList(new QueryWrapper<KwDevicePhoneSim>().eq("school_id", schoolId));
        PageBean<KwDevicePhoneSim> pageBean = new PageBean<>(phoneSimList);
        List<KwDevicePhoneSim> list = pageBean.getList();
        for (KwDevicePhoneSim sim : list) {
            int allDur = getCallDuration(sim.getSimNumber(), null, null, false);//所有时间
            int weekDur = getCallDuration(sim.getSimNumber(), fromDateWeek, toDateWeek, true);//当前星期
            int lastWeekDur = getCallDuration(sim.getSimNumber(), fromDateLastWeek, toDateLastWeek, false);//上星期
            int monthDur = getCallDuration(sim.getSimNumber(), fromDateMonth, toDateMonth, true);//当前月
            int lastMonthDur = getCallDuration(sim.getSimNumber(), fromDateLastMonth, toDateLastMoth, false);//上个月
            sim.setAllDur(allDur).setWeekDur(weekDur).setLastWeekDur(lastWeekDur).setMonthDur(monthDur).setLastMonthDur(lastMonthDur);
            sim.setRemaim(sim.getPackages()*60 - monthDur);
           List<KwAttendanceDevice> device = deviceMapper.selectList(new QueryWrapper<KwAttendanceDevice>().eq("sim_id", sim.getId()).eq("school_id", schoolId));
            if (device.size()>0){
                sim.setDeviceNo(device.get(0).getDeviceNo());
                sim.setLocation(device.get(0).getLocation());
            }
        }
        return pageBean;
    }

标签:java,format,simpleDateFormat,使用,new,Calendar,calendar,sim
来源: https://www.cnblogs.com/kltsee/p/16034049.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有