String yearMon="201506" Calendar c =Calendar.getInstance(); c.set(Calendar.YEAR,Integer.parseInt(yearMon.substring(0, 4))); c.set(Calendar.MONTH,Integer.parseInt(yearMon.substring(4, 6))-1); int days= c.getActualMaximum(Calendar.DAY_OF_MONTH);//获取当月的天数 c.set(Calendar.DATE,days); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String lastDate = sdf.format(c.getTime());//获取当月最后一天 c.clear(Calendar.DATE); c.add(Calendar.MONTH,-1); String lastMonth = new SimpleDateFormat("yyyyMM").format(c.getTime());