Browse Source

根据当前日期获得最近n周的日期区间优化

tags/正式3.2.5
雍文秀 2 years ago
parent
commit
53b590eea7
1 changed files with 4 additions and 1 deletions
  1. 4
    1
      scommons/src/main/java/com/xhkjedu/utils/DatesUtil.java

+ 4
- 1
scommons/src/main/java/com/xhkjedu/utils/DatesUtil.java View File

@@ -90,8 +90,11 @@ public class DatesUtil {
90 90
         Calendar calendar = Calendar.getInstance();
91 91
         calendar.setTime(date);
92 92
         int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
93
+        if (dayOfWeek == 0) {
94
+            dayOfWeek = 7;
95
+        }
93 96
         int offset = 0 == option ? 1 - dayOfWeek : 7 - dayOfWeek;
94
-        int amount = 0 == option ? offset - (n - 1  + k) * 7 : offset - k * 7;
97
+        int amount = 0 == option ? offset - (n - 1 + k) * 7 : offset - k * 7;
95 98
         calendar.add(Calendar.DATE, amount);
96 99
         return sdf.format(calendar.getTime());
97 100
     }

Loading…
Cancel
Save