上个月第一天和最后一天
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class TestController {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//获取当前月的第一天
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH,-1);
c.set(Calendar.DAY_OF_MONTH,1);
String dataStart = df.format(c.getTime());
//获取当月最后一天
Calendar c1 = Calendar.getInstance();
c1.add(Calendar.MONTH,-1);
c1.set(Calendar.DAY_OF_MONTH, c1.getActualMaximum(Calendar.DAY_OF_MONTH));
String dataEnd = df.format(c1.getTime());
}
}
当月第一天和最后一天:
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class TestController {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//获取当前月的第一天
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH,1);
String dataStart = df.format(c.getTime());
//获取当月最后一天
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.DAY_OF_MONTH, c1.getActualMaximum(Calendar.DAY_OF_MONTH));
String dataEnd = df.format(c1.getTime());
}
}