From a4d96fb3100e6aaf65e54d260921ceb1c00e54ef Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期二, 26 二月 2019 10:10:51 +0800
Subject: [PATCH] 免单商品/bug修复

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

diff --git a/utils/src/main/java/org/yeshi/utils/DateUtil.java b/utils/src/main/java/org/yeshi/utils/DateUtil.java
index 7030788..24148cf 100644
--- a/utils/src/main/java/org/yeshi/utils/DateUtil.java
+++ b/utils/src/main/java/org/yeshi/utils/DateUtil.java
@@ -126,6 +126,27 @@
 		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());
+	}
+	
 	/**
 	 * 鎸囧畾鏃ユ湡鍑忓幓澶╂暟鍚庣殑鏃ユ湡
 	 * 
@@ -146,6 +167,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));     
+    } 
 	
 	/**
 	 * 杩斿洖涓棿鏃ユ湡
@@ -176,4 +235,21 @@
 	}
 	
 	
+	/**
+     * @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