Ver código fonte

2023-3-30 优化一体机查询根据一周的日期归类返回。

chaiyunlong 2 anos atrás
pai
commit
b7a9341c28

+ 7 - 9
zd-modules/zd-base/src/main/java/com/zd/base/app/controller/LabBoardApi.java

@@ -337,15 +337,13 @@ public class LabBoardApi {
     }
 
     public List<Date> dateToWeek(Date mdate) {
-        int b = mdate.getDay();
-        Date fdate;
-        List<Date> list = new ArrayList<Date>();
-        Long fTime = mdate.getTime() - b * 24 * 3600000;
-        for (int a = 1; a <= 7; a++) {
-            fdate = new Date();
-            fdate.setTime(fTime + (a * 24 * 3600000));
-            list.add(a-1, fdate);
+        List<Date> allDate = new ArrayList <>();
+        for(int i=0;i<7;i++){
+            Calendar   calendar = new GregorianCalendar();
+            calendar.setTime(mdate);
+            calendar.add(calendar.DATE,i); //把日期往后增加一天,整数  往后推,负数往前移动
+            allDate.add(calendar.getTime());//这个时间就是日期往后推一天的结果
         }
-        return list;
+        return allDate;
     }
 }