Commit 65c08982 authored by pengfei_liu's avatar pengfei_liu
Browse files

#首页获取前6个月日期代码调整

parent 8d3d0314
...@@ -706,10 +706,7 @@ public class DepotItemController { ...@@ -706,10 +706,7 @@ public class DepotItemController {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
String message = "成功"; String message = "成功";
try { try {
Date date = new Date(); List<String> list = Tools.getLastMonths(6);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
String dateString = formatter.format(date);
List<String> list = Tools.getSixMonth(dateString);
map.put("monthList", list); map.put("monthList", list);
List<BigDecimal> buyPriceList = new ArrayList<BigDecimal>(); List<BigDecimal> buyPriceList = new ArrayList<BigDecimal>();
for(String month: list) { for(String month: list) {
......
...@@ -155,6 +155,27 @@ public class Tools { ...@@ -155,6 +155,27 @@ public class Tools {
return new SimpleDateFormat("yyyy-MM").format(cal.getTime()); return new SimpleDateFormat("yyyy-MM").format(cal.getTime());
} }
/**
* 获取当前月份的前6个月(含当前月)
* @param size 月数
* @return
*/
public static List<String> getLastMonths(int size) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Calendar c = Calendar.getInstance();
c.setTime(new Date());
List<String> list = new ArrayList(size);
for (int i=0;i<size;i++) {
c.setTime(new Date());
c.add(Calendar.MONTH, -i);
Date m = c.getTime();
list.add(sdf.format(m));
}
Collections.reverse(list);
return list;
}
/** /**
* 获取当前月份的前6个月(含当前月) * 获取当前月份的前6个月(含当前月)
* @param date * @param date
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment