[java]代码库
package test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class LastMonthDay {
public static void printLastMonthDay(){
Calendar calendar = Calendar.getInstance();
int month = calendar.get(Calendar.MONTH);
calendar.set(Calendar.MONTH, month-1);
calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date strDateTo = calendar.getTime();
String str=sdf.format(strDateTo);
System.out.println(str);
}
public static void main(String[] args) {
printLastMonthDay();
}
}