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 |  262 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 218 insertions(+), 44 deletions(-)

diff --git a/utils/src/main/java/org/yeshi/utils/DateUtil.java b/utils/src/main/java/org/yeshi/utils/DateUtil.java
index fa36db5..24148cf 100644
--- a/utils/src/main/java/org/yeshi/utils/DateUtil.java
+++ b/utils/src/main/java/org/yeshi/utils/DateUtil.java
@@ -2,80 +2,254 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
+import java.util.List;
 
 public class DateUtil {
-	
+
 	public static String dateDiff(String startTime, String endTime) {
-		
-		String datatime = 0 + "澶�" + 0 + "灏忔椂" + 0 + "鍒嗛挓" ;
+
+		String datatime = 0 + "澶�" + 0 + "灏忔椂" + 0 + "鍒嗛挓";
 		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-		
+
 		try {
-			long ns = 1000;// 涓�绉掗挓鐨勬绉掓暟
 			long nm = 1000 * 60;// 涓�鍒嗛挓鐨勬绉掓暟
 			long nh = 1000 * 60 * 60;// 涓�灏忔椂鐨勬绉掓暟
 			long nd = 1000 * 24 * 60 * 60;// 涓�澶╃殑姣鏁�
-			
+
 			// 鑾峰緱涓や釜鏃堕棿鐨勬绉掓椂闂村樊寮�
 			long diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
-		
+
 			long day = diff / nd;// 璁$畻宸灏戝ぉ
 			long hour = diff % nd / nh;// 璁$畻宸灏戝皬鏃�
 			long min = diff % nd % nh / nm;// 璁$畻宸灏戝垎閽�
-			long sec = diff % nd % nh % nm / ns;// 璁$畻宸灏戠
-			
-			//System.out.println("鏃堕棿鐩稿樊锛�" + day + "澶�" + hour + "灏忔椂" + min + "鍒嗛挓" + sec + "绉�");
-			
-			datatime = day + "澶�" + hour + "灏忔椂" + min + "鍒嗛挓" ;
-			
+
+			datatime = day + "澶�" + hour + "灏忔椂" + min + "鍒嗛挓";
+
 		} catch (ParseException e) {
-			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
-		
+
 		return datatime;
 	}
-	
-	
-	public static String dateDiff2(Date startTime, Date endTime) throws Exception{
-		
-		String datatime = 0 + "澶�" + 0 + "灏忔椂" + 0 + "鍒嗛挓" ;
-		
-		long ns = 1000;// 涓�绉掗挓鐨勬绉掓暟
+
+	public static String dateDiff2(Date startTime, Date endTime) throws Exception {
+
+		String datatime = 0 + "澶�" + 0 + "灏忔椂" + 0 + "鍒嗛挓";
+
 		long nm = 1000 * 60;// 涓�鍒嗛挓鐨勬绉掓暟
 		long nh = 1000 * 60 * 60;// 涓�灏忔椂鐨勬绉掓暟
 		long nd = 1000 * 24 * 60 * 60;// 涓�澶╃殑姣鏁�
-		
+
 		// 鑾峰緱涓や釜鏃堕棿鐨勬绉掓椂闂村樊寮�
 		long diff = endTime.getTime() - startTime.getTime();
-	
+
 		long day = diff / nd;// 璁$畻宸灏戝ぉ
 		long hour = diff % nd / nh;// 璁$畻宸灏戝皬鏃�
 		long min = diff % nd % nh / nm;// 璁$畻宸灏戝垎閽�
-		
-		
-		datatime = day + "澶�" + hour + "灏忔椂" + min + "鍒嗛挓" ;
-			
-		
+
+		datatime = day + "澶�" + hour + "灏忔椂" + min + "鍒嗛挓";
+
 		return datatime;
 	}
 	
-	public String transferLongToDate(String dateFormat, Long millSec) {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date date = new Date(millSec);
-        return sdf.format(date);
+	/**
+	 * 閫氳繃鏃堕棿绉掓绉掓暟鍒ゆ柇涓や釜鏃堕棿鐨勯棿闅�
+     * @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);
+		return sdf.format(date);
+	}
 
-	 public static void main(String[] args) {  
-		 long a= 1529044851008L;
-		 Long l = new Long(a);
-		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-	     Date date = new Date(l);
-	     System.out.println(sdf.format(date));
-		 new DateUtil().dateDiff(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()), sdf.format(date));  
-	 }  
+	/**
+	 * 楠岃瘉鏄惁灞炰簬鍚屼竴澶�
+	 * 
+	 * @param date1
+	 * @param date2
+	 * @return
+	 */
+	public static boolean isSameDay(Date date1, Date date2) {
+		if (date1 != null && date2 != null) {
+			Calendar cal1 = Calendar.getInstance();
+			cal1.setTime(date1);
+			Calendar cal2 = Calendar.getInstance();
+			cal2.setTime(date2);
+			return isSameDay(cal1, cal2);
+		} else {
+			return false;
+		}
+	}
+
+	/**
+	 * 楠岃瘉鏄惁灞炰簬鍚屼竴澶�
+	 * 
+	 * @param cal1
+	 * @param cal2
+	 * @return
+	 */
+	public static boolean isSameDay(Calendar cal1, Calendar cal2) {
+		if (cal1 != null && cal2 != null) {
+			return cal1.get(0) == cal2.get(0) && cal1.get(1) == cal2.get(1) && cal1.get(6) == cal2.get(6);
+		} else {
+			return false;
+		}
+	}
+	
+	/**
+	 * 鎸囧畾鏃ユ湡鍔犱笂澶╂暟鍚庣殑鏃ユ湡
+	 * 
+	 * @param num
+	 *            澧炲姞鐨勫ぉ鏁�
+	 * @param nowDate
+	 *            鍒涘缓鏃堕棿
+	 * @return
+	 * @throws ParseException
+	 */
+	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);
+		ca.add(Calendar.DATE, num);
+		
+		return format.format(ca.getTime());
+	}
+	
+	/**
+	 * 鎸囧畾鏃ユ湡鍑忓幓澶╂暟鍚庣殑鏃ユ湡
+	 * 
+	 * @param num
+	 *            鍑忓幓鐨勫ぉ鏁�
+	 * @param nowDate
+	 *            鍒涘缓鏃堕棿
+	 * @return
+	 * @throws ParseException
+	 */
+	public static String reduceDay(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 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