From d36d1adfd749fed26923f7e3664a36d405b0acfe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 08 五月 2019 16:05:17 +0800
Subject: [PATCH] 大淘客数据修改,热销推广商品接口修改

---
 utils/src/main/java/org/yeshi/utils/DateUtil.java |  126 +++++++++++++++++++++++++++++------------
 1 files changed, 88 insertions(+), 38 deletions(-)

diff --git a/utils/src/main/java/org/yeshi/utils/DateUtil.java b/utils/src/main/java/org/yeshi/utils/DateUtil.java
index 3cfbc90..24148cf 100644
--- a/utils/src/main/java/org/yeshi/utils/DateUtil.java
+++ b/utils/src/main/java/org/yeshi/utils/DateUtil.java
@@ -54,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);
@@ -95,42 +105,6 @@
 		}
 	}
 	
-	
-	/**
-	 * 楠岃瘉鏄惁灞炰簬鍚屼竴澶�
-	 * 
-	 * @param Date1
-	 * @param Date2
-	 * @return
-	 */
-	public static boolean isSameMonth(Date date1, Date date2) {
-		if (date1 != null && date2 != null) {
-			Calendar cal1 = Calendar.getInstance();
-			cal1.setTime(date1);
-			Calendar cal2 = Calendar.getInstance();
-			cal2.setTime(date2);
-			return isSameMonth(cal1, cal2);
-		} else {
-			return false;
-		}
-	}
-	
-	/**
-	 * 楠岃瘉鏄惁灞炰簬鍚屽勾鍚屾湀
-	 * 
-	 * @param cal1
-	 * @param cal2
-	 * @return
-	 */
-	public static boolean isSameMonth(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;
-		}
-	}
-	
-
 	/**
 	 * 鎸囧畾鏃ユ湡鍔犱笂澶╂暟鍚庣殑鏃ユ湡
 	 * 
@@ -144,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);
@@ -173,6 +168,44 @@
 		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
@@ -198,8 +231,25 @@
 				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