根据所需的格式进行转换
//上个月第一天凌晨时间
@Test
public void getLastMonthFirstDay() {
Calendar cal = Calendar.getInstance();
cal.add(cal.MONTH, -1);
cal.set(cal.DAY_OF_MONTH, 1);
SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
String lastMonth = dft.format(cal.getTime());
System.out.println(lastMonth);
}
//上个月最后一天凌晨时间
@Test
public void getLastMonthLastDay() {
SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
Calendar cale = Calendar.getInstance();
cale.set(Calendar.DAY_OF_MONTH, 0);
String lastDay = dft.format(cale.getTime());
System.out.println(lastDay);
}