From ed8ce63fd54a7c4ca734198e0b4d6f81a0b7af9e Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 20 五月 2024 08:51:23 +0800
Subject: [PATCH] 提交一把
---
server/service/src/main/java/com/doumee/core/utils/DateUtil.java | 39 +++++++++++++++++++++++++++++++++++----
1 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/server/service/src/main/java/com/doumee/core/utils/DateUtil.java b/server/service/src/main/java/com/doumee/core/utils/DateUtil.java
index 1acf22d..0c8a385 100644
--- a/server/service/src/main/java/com/doumee/core/utils/DateUtil.java
+++ b/server/service/src/main/java/com/doumee/core/utils/DateUtil.java
@@ -1,6 +1,8 @@
package com.doumee.core.utils;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
@@ -8,6 +10,7 @@
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
+import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
@@ -3186,8 +3189,17 @@
// );
- LocalDate startDate= LocalDate.of(2021,2,28);
- LocalDate endDate =LocalDate.of(2022,4,5);
+// System.out.println(
+// new BigDecimal(16).divide(new BigDecimal(15.5),0, RoundingMode.CEILING)
+// );
+ LocalDate startDate = DateUtil.StringToDate("2021-02-28 23:59:59").toInstant()
+ .atZone(ZoneId.systemDefault())
+ .toLocalDate();
+ LocalDate endDate = DateUtil.StringToDate("2022-04-05 23:59:59").toInstant()
+ .atZone(ZoneId.systemDefault())
+ .toLocalDate();
+// LocalDate startDate= LocalDate.of(2021,2,28);
+// LocalDate endDate =LocalDate.of(2022,4,5);
Period period = Period.between(startDate,endDate);
int months = period.getYears()* 12 + period.getMonths();
System.out.println("Months between the two dates: " + months);
@@ -3214,9 +3226,28 @@
//
// );
-
-
}
+ /**
+ * 鑾峰彇鐩稿樊鐨勬湀鏁�
+ * @param sDate
+ * @param eDate
+ * @return
+ */
+ public static Integer getDifferenceMonths(Date sDate ,Date eDate) {
+ LocalDate startDate = sDate.toInstant()
+ .atZone(ZoneId.systemDefault())
+ .toLocalDate();
+ LocalDate endDate = eDate.toInstant()
+ .atZone(ZoneId.systemDefault())
+ .toLocalDate();
+// LocalDate startDate= LocalDate.of(2021,2,28);
+// LocalDate endDate =LocalDate.of(2022,4,5);
+ Period period = Period.between(endDate,startDate);
+ int months = period.getYears()* 12 + period.getMonths();
+ return months + 1;
+ }
+
+
}
\ No newline at end of file
--
Gitblit v1.9.3