From 8b1dffc0ce5787d74020ac8a1c6ed00f16a7a0f4 Mon Sep 17 00:00:00 2001 From: k94314517 <8417338+k94314517@user.noreply.gitee.com> Date: 星期六, 17 五月 2025 18:28:55 +0800 Subject: [PATCH] git ch --- server/service/src/main/java/com/doumee/core/utils/DateUtil.java | 226 ++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 136 insertions(+), 90 deletions(-) diff --git a/server/service/src/main/java/com/doumee/core/utils/DateUtil.java b/server/service/src/main/java/com/doumee/core/utils/DateUtil.java index fa297b0..6860dfb 100644 --- a/server/service/src/main/java/com/doumee/core/utils/DateUtil.java +++ b/server/service/src/main/java/com/doumee/core/utils/DateUtil.java @@ -113,6 +113,33 @@ } } + public static long getBetweenMin(Date fromDate, Date toDate) { + long m_intervalday = 0;// 鍒濆鍖栨椂闂撮棿闅旂殑鍊间负0 + // 浣跨敤鐨勬椂闂存牸寮忎负yyyy-MM-dd + try { + m_intervalday = toDate.getTime() - fromDate.getTime();// 璁$畻鎵�寰椾负寰鏁� + m_intervalday = m_intervalday / 1000 / 60 ;// 璁$畻鎵�寰楃殑澶╂暟 + + return m_intervalday + 1; + } catch (Exception e) { + return Integer.MIN_VALUE; + } + } + + + public static long getBetweenDay(Date fromDate, Date toDate) { + long m_intervalday = 0;// 鍒濆鍖栨椂闂撮棿闅旂殑鍊间负0 + // 浣跨敤鐨勬椂闂存牸寮忎负yyyy-MM-dd + try { + m_intervalday = toDate.getTime() - fromDate.getTime();// 璁$畻鎵�寰椾负寰鏁� + m_intervalday = m_intervalday / 1000 / 60 / 60 / 24 ;// 璁$畻鎵�寰楃殑澶╂暟 + + return m_intervalday + 1; + } catch (Exception e) { + return Integer.MIN_VALUE; + } + } + /** * @author Pablo Descrption:取锟矫碉拷前锟斤拷锟斤拷getgetg get Date format * Example锛�2008.03.15 @@ -889,95 +916,95 @@ * @return 杞崲寰楀埌鐨勬棩鏈� */ @SuppressWarnings("unchecked") - public static Date stringToDate(String strDate, String oracleFormat) { - if (strDate == null) - return null; - Hashtable<Integer, String> h = new Hashtable<Integer, String>(); - String javaFormat = new String(); - String s = oracleFormat.toLowerCase(); - if (s.indexOf("yyyy") != -1) - h.put(new Integer(s.indexOf("yyyy")), "yyyy"); - else if (s.indexOf("yy") != -1) - h.put(new Integer(s.indexOf("yy")), "yy"); - if (s.indexOf("mm") != -1) - h.put(new Integer(s.indexOf("mm")), "MM"); - - if (s.indexOf("dd") != -1) - h.put(new Integer(s.indexOf("dd")), "dd"); - if (s.indexOf("hh24") != -1) - h.put(new Integer(s.indexOf("hh24")), "HH"); - if (s.indexOf("mi") != -1) - h.put(new Integer(s.indexOf("mi")), "mm"); - if (s.indexOf("ss") != -1) - h.put(new Integer(s.indexOf("ss")), "ss"); - - int intStart = 0; - while (s.indexOf("-", intStart) != -1) { - intStart = s.indexOf("-", intStart); - h.put(new Integer(intStart), "-"); - intStart++; - } - - intStart = 0; - while (s.indexOf("/", intStart) != -1) { - intStart = s.indexOf("/", intStart); - h.put(new Integer(intStart), "/"); - intStart++; - } - - intStart = 0; - while (s.indexOf(" ", intStart) != -1) { - intStart = s.indexOf(" ", intStart); - h.put(new Integer(intStart), " "); - intStart++; - } - - intStart = 0; - while (s.indexOf(":", intStart) != -1) { - intStart = s.indexOf(":", intStart); - h.put(new Integer(intStart), ":"); - intStart++; - } - - if (s.indexOf("骞�") != -1) - h.put(new Integer(s.indexOf("骞�")), "骞�"); - if (s.indexOf("鏈�") != -1) - h.put(new Integer(s.indexOf("鏈�")), "鏈�"); - if (s.indexOf("鏃�") != -1) - h.put(new Integer(s.indexOf("鏃�")), "鏃�"); - if (s.indexOf("鏃�") != -1) - h.put(new Integer(s.indexOf("鏃�")), "鏃�"); - if (s.indexOf("鍒�") != -1) - h.put(new Integer(s.indexOf("鍒�")), "鍒�"); - if (s.indexOf("绉�") != -1) - h.put(new Integer(s.indexOf("绉�")), "绉�"); - - int i = 0; - while (h.size() != 0) { - Enumeration e = h.keys(); - int n = 0; - while (e.hasMoreElements()) { - i = ((Integer) e.nextElement()).intValue(); - if (i >= n) - n = i; - } - String temp = (String) h.get(new Integer(n)); - h.remove(new Integer(n)); - - javaFormat = temp + javaFormat; - } - SimpleDateFormat df = new SimpleDateFormat(javaFormat); - - Date myDate = new Date(); - try { - myDate = df.parse(strDate); - } catch (Exception e) { - // e.printStackTrace(); - return null; - } - - return myDate; - } +// public static Date stringToDate(String strDate, String oracleFormat) { +// if (strDate == null) +// return null; +// Hashtable<Integer, String> h = new Hashtable<Integer, String>(); +// String javaFormat = new String(); +// String s = oracleFormat.toLowerCase(); +// if (s.indexOf("yyyy") != -1) +// h.put(new Integer(s.indexOf("yyyy")), "yyyy"); +// else if (s.indexOf("yy") != -1) +// h.put(new Integer(s.indexOf("yy")), "yy"); +// if (s.indexOf("mm") != -1) +// h.put(new Integer(s.indexOf("mm")), "MM"); +// +// if (s.indexOf("dd") != -1) +// h.put(new Integer(s.indexOf("dd")), "dd"); +// if (s.indexOf("hh24") != -1) +// h.put(new Integer(s.indexOf("hh24")), "HH"); +// if (s.indexOf("mi") != -1) +// h.put(new Integer(s.indexOf("mi")), "mm"); +// if (s.indexOf("ss") != -1) +// h.put(new Integer(s.indexOf("ss")), "ss"); +// +// int intStart = 0; +// while (s.indexOf("-", intStart) != -1) { +// intStart = s.indexOf("-", intStart); +// h.put(new Integer(intStart), "-"); +// intStart++; +// } +// +// intStart = 0; +// while (s.indexOf("/", intStart) != -1) { +// intStart = s.indexOf("/", intStart); +// h.put(new Integer(intStart), "/"); +// intStart++; +// } +// +// intStart = 0; +// while (s.indexOf(" ", intStart) != -1) { +// intStart = s.indexOf(" ", intStart); +// h.put(new Integer(intStart), " "); +// intStart++; +// } +// +// intStart = 0; +// while (s.indexOf(":", intStart) != -1) { +// intStart = s.indexOf(":", intStart); +// h.put(new Integer(intStart), ":"); +// intStart++; +// } +// +// if (s.indexOf("骞�") != -1) +// h.put(new Integer(s.indexOf("骞�")), "骞�"); +// if (s.indexOf("鏈�") != -1) +// h.put(new Integer(s.indexOf("鏈�")), "鏈�"); +// if (s.indexOf("鏃�") != -1) +// h.put(new Integer(s.indexOf("鏃�")), "鏃�"); +// if (s.indexOf("鏃�") != -1) +// h.put(new Integer(s.indexOf("鏃�")), "鏃�"); +// if (s.indexOf("鍒�") != -1) +// h.put(new Integer(s.indexOf("鍒�")), "鍒�"); +// if (s.indexOf("绉�") != -1) +// h.put(new Integer(s.indexOf("绉�")), "绉�"); +// +// int i = 0; +// while (h.size() != 0) { +// Enumeration e = h.keys(); +// int n = 0; +// while (e.hasMoreElements()) { +// i = ((Integer) e.nextElement()).intValue(); +// if (i >= n) +// n = i; +// } +// String temp = (String) h.get(new Integer(n)); +// h.remove(new Integer(n)); +// +// javaFormat = temp + javaFormat; +// } +// SimpleDateFormat df = new SimpleDateFormat(javaFormat); +// +// Date myDate = new Date(); +// try { +// myDate = df.parse(strDate); +// } catch (Exception e) { +// // e.printStackTrace(); +// return null; +// } +// +// return myDate; +// } public static Date StringToDate(String DATE1) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); @@ -3084,7 +3111,25 @@ return cal.getTime(); } + /** + * 鑾峰彇鏌愪釜鏃堕棿X鍒嗛挓鍚庣殑鏃堕棿 + * @param minutes + * @param date + * @return + */ + public static Date afterMinutesByDate(Integer minutes,Date date){ + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.MINUTE,minutes); + return cal.getTime(); + } + public static Date afterDayByDate(Integer days,Date date){ + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.DATE,days); + return cal.getTime(); + } /** * 璁$畻澶氬皯鑷劧骞�/鏈�/鏃ュ悗鐨勬棩鏈� * @param startDate 寮�濮嬫棩鏈� @@ -3157,7 +3202,8 @@ public static void main(String[] args) throws Exception{ - System.out.println(DateUtil.getLongDateTime(new Date()));; + System.out.println(DateUtil.StringToDate("2025-05-16 13:49:40").getTime()); +// System.out.println(DateUtil.getLongDateTime(new Date()));; } /** -- Gitblit v1.9.3