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};
}
根據當前日期得到本月月末、上月月末。。。。。。。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.