本文为博主原创,转载请注明出处
public static Map<String,String> getMonthMap(int month){ Map<String,String> monthMap = new HashMap<>(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // 获取前月的第一天 Calendar cal_1 = Calendar.getInstance();// 获取当前日期 cal_1.add(Calendar.MONTH, -month); cal_1.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天 String firstDay = format.format(cal_1.getTime()); // 获取前月的最后一天 Calendar cale = Calendar.getInstance(); cale.add(Calendar.MONTH, -(month-1)); cale.set(Calendar.DAY_OF_MONTH, 0); String lastDay = format.format(cale.getTime()); monthMap.put("firstDay", firstDay); monthMap.put("lastDay", lastDay); return monthMap; }