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 | 88 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 1 deletions(-) diff --git a/utils/src/main/java/org/yeshi/utils/DateUtil.java b/utils/src/main/java/org/yeshi/utils/DateUtil.java index ca60d74..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); @@ -116,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()); + } + /** * 鎸囧畾鏃ユ湡鍑忓幓澶╂暟鍚庣殑鏃ユ湡 * @@ -136,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)); + } /** * 杩斿洖涓棿鏃ユ湡 @@ -166,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