From d2ee731b6a64fa002bceddebf0cc59c78b6c17ce Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 27 二月 2019 10:12:31 +0800
Subject: [PATCH] 邀请成功消息提醒

---
 utils/src/main/java/org/yeshi/utils/DateUtil.java |  122 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/utils/src/main/java/org/yeshi/utils/DateUtil.java b/utils/src/main/java/org/yeshi/utils/DateUtil.java
index 65596e2..24148cf 100644
--- a/utils/src/main/java/org/yeshi/utils/DateUtil.java
+++ b/utils/src/main/java/org/yeshi/utils/DateUtil.java
@@ -2,8 +2,10 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 
 public class DateUtil {
 
@@ -52,7 +54,17 @@
 
 		return datatime;
 	}
-
+	
+	/**
+	 * 閫氳繃鏃堕棿绉掓绉掓暟鍒ゆ柇涓や釜鏃堕棿鐨勯棿闅�
+     * @param date1
+     * @param date2
+     * @return
+     */
+    public static int differentDaysByMillisecond(Date start, Date end) {
+    	return (int) ((end.getTime() - start.getTime()) / (1000*3600*24));
+    }
+	
 	public String transferLongToDate(String dateFormat, Long millSec) {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 		Date date = new Date(millSec);
@@ -92,7 +104,7 @@
 			return false;
 		}
 	}
-
+	
 	/**
 	 * 鎸囧畾鏃ユ湡鍔犱笂澶╂暟鍚庣殑鏃ユ湡
 	 * 
@@ -106,6 +118,27 @@
 	public static String plusDay(int num, String nowDate) throws ParseException {
 		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
 		Date currdate = format.parse(nowDate);
+	
+		Calendar ca = Calendar.getInstance();
+		ca.setTime(currdate);
+		ca.add(Calendar.DATE, num);
+		
+		return format.format(ca.getTime());
+	}
+	
+	
+	/**
+	 * 鎸囧畾鏃ユ湡鍔犱笂澶╂暟鍚庣殑鏃ユ湡
+	 * 
+	 * @param num
+	 *            澧炲姞鐨勫ぉ鏁�
+	 * @param nowDate
+	 *            鍒涘缓鏃堕棿
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String plusDay(int num, Date currdate) throws ParseException {
+		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
 	
 		Calendar ca = Calendar.getInstance();
 		ca.setTime(currdate);
@@ -134,4 +167,89 @@
 		
 		return format.format(ca.getTime());
 	}
+	
+	  /**
+     * 璁$畻涓や釜鏃ユ湡涔嬮棿鐩稿樊鐨勫ぉ鏁�  
+     * @param smdate 杈冨皬鐨勬椂闂� 
+     * @param bdate  杈冨ぇ鐨勬椂闂� 
+     * @return 鐩稿樊澶╂暟 
+     * @throws ParseException  
+     * calendar 瀵规棩鏈熻繘琛屾椂闂存搷浣�
+     * getTimeInMillis() 鑾峰彇鏃ユ湡鐨勬绉掓樉绀哄舰寮�
+     */
+    public static int daysBetween(Date smdate,Date bdate) throws ParseException    
+    {    
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(smdate);
+        long time1 = cal.getTimeInMillis();
+        cal.setTime(bdate);
+        long time2 = cal.getTimeInMillis();      
+        long between_days=(time2-time1)/(1000*3600*24);  
+        return Integer.parseInt(String.valueOf(between_days));           
+    }
+    
+    /**
+     * 瀛楃涓叉棩鏈熸牸寮忕殑璁$畻
+     * @param smdate
+     * @param bdate
+     * @return
+     * @throws ParseException
+     */
+    public static int daysBetween(String smdate,String bdate) throws ParseException{  
+        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
+        Calendar cal = Calendar.getInstance();    
+        cal.setTime(sdf.parse(smdate));    
+        long time1 = cal.getTimeInMillis();                 
+        cal.setTime(sdf.parse(bdate));    
+        long time2 = cal.getTimeInMillis();         
+        long between_days=(time2-time1)/(1000*3600*24);  
+        return Integer.parseInt(String.valueOf(between_days));     
+    } 
+	
+	/**
+	 * 杩斿洖涓棿鏃ユ湡
+	 * @param startTime
+	 * @param endTime
+	 * @return
+	 * @throws Exception
+	 */
+	public static List<String> dayFactory(String startTime, String endTime) throws Exception {
+
+		List<String> listDate = new ArrayList<String>();
+
+		String plusDay = "";
+		for (int i = 0; i < 1000; i++) {
+			if (i == 0) {
+				plusDay = startTime;
+			} else {
+				plusDay = DateUtil.plusDay(i, startTime);
+			}
+
+			listDate.add(plusDay);
+
+			if (plusDay.equals(endTime)) {
+				break; // 鏃堕棿缁撴潫
+			}
+		}
+		return listDate;
+	}
+	
+	
+	/**
+     * @param args
+     * @throws ParseException
+     * format() 瀵规棩鏈熻繘琛屾牸寮忓寲澶勭悊
+     * parse() 灏嗘棩鏈熻缃负date绫诲瀷
+     */
+    public static void main(String[] args) throws ParseException {  
+        // TODO Auto-generated method stub  
+        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
+        Date d1=sdf.parse("2016-09-08 00:00:00");  
+        Date d2=sdf.parse("2016-09-08 00:00:00");
+        
+        System.out.println(daysBetween(d1,d2));  
+        System.out.println(daysBetween("2016-09-08 10:10:10","2016-09-29 00:00:00")); 
+    }  
+
+	
 }
\ No newline at end of file

--
Gitblit v1.8.0