From 98118c2bf5343dde3dbf48c20bc8a0fd69cfedbd Mon Sep 17 00:00:00 2001 From: E1ED922C1E9526DD63272D7EC5C6CB77 <E1ED922C1E9526DD63272D7EC5C6CB77@i-search.com.cn> Date: 星期一, 14 十二月 2020 10:12:42 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/huoxiong/hx_common --- src/main/java/com/hx/util/DateUtil.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/util/DateUtil.java b/src/main/java/com/hx/util/DateUtil.java index f387926..a2484b8 100644 --- a/src/main/java/com/hx/util/DateUtil.java +++ b/src/main/java/com/hx/util/DateUtil.java @@ -295,6 +295,19 @@ return c.getTime(); } + /**鏃堕棿涓婂勾鏁板彔鍔� + * @Author: ChenJiaHe + * @param dateTime 鏃堕棿 + * @param dayNum 澶╂暟 + * @return + */ + public static Date addYear(Date dateTime,int dayNum){ + Calendar c = Calendar.getInstance(); + c.setTime(dateTime); + c.add(Calendar.YEAR, dayNum); + return c.getTime(); + } + /** * 杞崲鎴愬瓧绗︿覆鍒版寚瀹氱殑鏃ユ湡 * @@ -354,6 +367,42 @@ return weekDays[w]; } + /** + * endTime姣攕tartTime澶氱殑澶╂暟 + * @param startTime 鏈�灏忔椂闂� + * @param endTime 鏈�澶ф椂闂� + * @return + */ + public static Integer differDay(Date startTime,Date endTime){ + Calendar cal1 = Calendar.getInstance(); + cal1.setTime(startTime); + + Calendar cal2 = Calendar.getInstance(); + cal2.setTime(endTime); + int day1= cal1.get(Calendar.DAY_OF_YEAR); + int day2 = cal2.get(Calendar.DAY_OF_YEAR); + + int year1 = cal1.get(Calendar.YEAR); + int year2 = cal2.get(Calendar.YEAR); + if(year1 != year2) { //鍚屼竴骞� + int timeDistance = 0 ; + for(int i = year1 ; i < year2 ; i ++) { + if(i%4==0 && i%100!=0 || i%400==0) {//闂板勾 + timeDistance += 366; + } + else {//涓嶆槸闂板勾 + timeDistance += 365; + } + } + + return timeDistance + (day2-day1) ; + } + else { //涓嶅悓骞� + System.out.println("鍒ゆ柇day2 - day1 : " + (day2-day1)); + return day2-day1; + } + } + /**鍒ゆ柇涓や釜鏃堕棿鏄笉鏄悓涓�澶�*/ public static boolean timeEqual(Date startTime,Date endTime){ if(startTime == null || endTime==null){ -- Gitblit v1.8.0