private EZPageRequest getStartAndEndDate() { EZPageRequest pageRequest = new EZPageRequest(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); Date time2 = calendar.getTime(); //当前时间 String currentTime = format.format(time2); log.info("当前时间--{}",currentTime); pageRequest.setCurrentDate(currentTime); //获取今年的第一天 清除时间为初始时间值 calendar.clear(); //将初始年份设置为当前年份 Calendar currCal=Calendar.getInstance(); calendar.set(Calendar.YEAR,currCal.get(Calendar.YEAR)); Date time = calendar.getTime(); String firstDay = format.format(time); log.info("今年的第一天--{}",firstDay); pageRequest.setThisDate(firstDay); //获取去年同期时间 年份减一 Calendar endCal= Calendar.getInstance(); endCal.set(Calendar.YEAR,currCal.get(Calendar.YEAR)); endCal.roll(Calendar.YEAR, -1); Date time1 = endCal.getTime(); String format1 = format.format(time1); pageRequest.setEndTime(format1); log.info("去年同期时间--{}",format1); //获取去年第一天时间 Calendar instance = Calendar.getInstance(); instance.clear(); instance.set(Calendar.YEAR,currCal.get(Calendar.YEAR)); instance.roll(Calendar.YEAR, -1); String endDate = format.format(instance.getTime()); pageRequest.setStartTime(endDate); log.info("去年的第一天--{}",endDate); return pageRequest; }