private String[] getActdates(String actdate) {//actdate格式为:2016-10
SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Date d = new Date();
try {
d = sf1.parse(actdate);
} catch (ParseException e) {
e.printStackTrace();
}
GregorianCalendar gc=new GregorianCalendar();
//得到上月的最后一天
gc.setTime(d);
gc.add(2,-1);
gc.set(gc.get(Calendar.YEAR),gc.get(Calendar.MONTH),gc.getActualMaximum(Calendar.DAY_OF_MONTH));
String lastmonthActdate = sf.format(gc.getTime());
//得到本月的最后一天
gc.setTime(d);
gc.set(gc.get(Calendar.YEAR),gc.get(Calendar.MONTH),gc.getActualMaximum(Calendar.DAY_OF_MONTH));
String curmonthActdate = sf.format(gc.getTime());
//得到去年的最后一天
gc.setTime(d);
gc.add(1,-1);
gc.set(gc.get(Calendar.YEAR),11,31);
String lastyearActdate = sf.format(gc.getTime());
//得到去年本月的最后一天
gc.setTime(d);
gc.add(1,-1);
gc.set(gc.get(Calendar.YEAR),gc.get(Calendar.MONTH),gc.getActualMaximum(Calendar.DAY_OF_MONTH));
String lastActdate = sf.format(gc.getTime());
return new String[]{lastmonthActdate, curmonthActdate, lastyearActdate, lastActdate};
}
根据当前日期得到本月月末、上月月末。。。。。。。
最新推荐文章于 2021-01-19 21:13:33 发布