From a78f187833591f3474c431861c7f889d399d9914 Mon Sep 17 00:00:00 2001 From: wangxy <1481820854@qq.com> Date: Fri, 18 Oct 2024 09:36:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=BB=9F=E8=AE=A1=E8=BF=91=E7=BA=BF?= =?UTF-8?q?=E4=B8=8A=E4=BC=9A=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/ObtainLastSixMonthsUtil.java | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java index f275f8d..ba7ed4e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ObtainLastSixMonthsUtil.java @@ -10,9 +10,7 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.temporal.ChronoField; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; /** @@ -38,6 +36,7 @@ public class ObtainLastSixMonthsUtil { String dateMonth = DateUtil.format(dateTime, "yyyy-MM"); previousMonths.add(dateMonth); } + Collections.sort(previousMonths); return previousMonths; } @@ -46,7 +45,7 @@ public class ObtainLastSixMonthsUtil { * * @return List */ - public static List getRecentlySixMonth() { + public static List getRecentlySixMonth2() { List previousMonths = new ArrayList<>(); String currentMonth = DateUtil.format(LocalDateTime.now(), "yyyy-MM"); previousMonths.add(currentMonth); @@ -55,6 +54,7 @@ public class ObtainLastSixMonthsUtil { String dateMonth = DateUtil.format(dateTime, "yyyy-MM"); previousMonths.add(dateMonth); } + Collections.sort(previousMonths); return previousMonths; } @@ -106,11 +106,38 @@ public class ObtainLastSixMonthsUtil { return DateUtil.between(nowDate, endDate, DateUnit.HOUR); } + /** + * 取近本年12个月的日期 + * @return + */ + public static List getRecentlySixMonth() { + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + List list = new ArrayList<>(); + for (int i = 1; i < 13; i++) { + String month = i + ""; + if (i < 10) { + month = "0" + i; + } + list.add(year + "-" + month); + } + return list; + } + + public static void main(String[] args) { - // System.out.println(getRecentlySixMonth()); List recentlySixMonth = getRecentlySixMonth(); recentlySixMonth.forEach(s -> System.out.println(getLastDayOfMonth(s))); + + /* List yearMonth = getYearMonth(); + for (int i = 0; i < yearMonth.size(); i++) { + System.out.println(yearMonth.get(i)); + }*/ } + + + + }