通过Calendar 实现
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar= Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
System.out.println("上个月第一天:"+format.format(calendar.getTime()));
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
System.out.println("上个月最后一天:"+format.format(calendar.getTime()));