From 5db5a84cee050795051a27181982bcc9a64ff19e Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期一, 17 二月 2025 11:28:38 +0800 Subject: [PATCH] jtt808初始化 --- server/services/src/main/java/com/doumee/core/utils/DateUtil.java | 61 ++++++++++++++++++++++++++++-- 1 files changed, 57 insertions(+), 4 deletions(-) diff --git a/server/services/src/main/java/com/doumee/core/utils/DateUtil.java b/server/services/src/main/java/com/doumee/core/utils/DateUtil.java index c101128..689c112 100644 --- a/server/services/src/main/java/com/doumee/core/utils/DateUtil.java +++ b/server/services/src/main/java/com/doumee/core/utils/DateUtil.java @@ -10,6 +10,9 @@ import java.text.DateFormatSymbols; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Date; import java.util.*; @@ -39,7 +42,18 @@ public DateUtil() { } + public static Date getDateFromLocalDateTime( LocalDateTime localDateTime) { + try { + ZoneId zoneId = ZoneId.systemDefault(); // 鑾峰彇绯荤粺榛樿鏃跺尯 + ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); // 杞崲涓哄甫鏃跺尯鐨勬棩鏈熸椂闂� + Date date = Date.from(zonedDateTime.toInstant()); // 杞崲涓篋ate + return date; + }catch (Exception e){ + } + return null; + + } public static Date StringToDate2(String DATE) { if(StringUtils.isBlank(DATE)){ return null; @@ -299,7 +313,7 @@ nowDate = sdfShort.format(date); return nowDate; } catch (Exception e) { - throw e; + return null; } } @@ -2309,7 +2323,7 @@ } public static Date getDateFromString2(String strDate) { if (StringUtils.isEmpty(strDate)) { - return new Date(System.currentTimeMillis()); + return null; } try { return sdfLongTimePlus.parse(strDate); @@ -2748,7 +2762,8 @@ public static void main(String[] args) { try { - System.out.println(RandomStringUtils.randomNumeric(3)); + System.out.println((int)(3.222)); + } catch (Exception ex) { ex.printStackTrace(); } @@ -3003,6 +3018,44 @@ return cal.getTime(); } + + /** + * 2涓棩鏈熶箣闂寸浉宸垎閽熸暟 + * @param begin + * @param end + * @return + */ + public static Integer betweenMin(Date begin, Date end) { + if(begin ==null ){ + return 0; + } + long createTime =begin.getTime();//鑾峰彇鍒涘缓鏃堕棿鐨勬椂闂存埑 + long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//鑾峰彇褰撳墠鏃堕棿鐨勬椂闂存埑 + long diff=(currentTime-createTime)/1000/60;//鑾峰彇涓や釜鏃堕棿鐩稿樊鐨勫垎閽� + return (int)diff + 1 ; + } + + public static Integer between(Date begin, Date end) { + if(begin ==null ){ + return 0; + } + long createTime =begin.getTime();//鑾峰彇鍒涘缓鏃堕棿鐨勬椂闂存埑 + long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//鑾峰彇褰撳墠鏃堕棿鐨勬椂闂存埑 + long diff=(currentTime-createTime)/1000/60;//鑾峰彇涓や釜鏃堕棿鐩稿樊鐨勫垎閽� + return (int)diff; + } + + public static Integer betweenSeconds(Date begin, Date end) { + if(begin ==null ){ + return 0; + } + long createTime =begin.getTime();//鑾峰彇鍒涘缓鏃堕棿鐨勬椂闂存埑 + long currentTime =Objects.isNull(end)?System.currentTimeMillis():end.getTime();//鑾峰彇褰撳墠鏃堕棿鐨勬椂闂存埑 + long diff=(currentTime-createTime)/1000;//鑾峰彇涓や釜鏃堕棿鐩稿樊鐨勫垎閽� + return (int)diff; + } + + /** * 璁$畻鑰楁椂 * @param start @@ -3022,4 +3075,4 @@ return consuming.toString(); } -} \ No newline at end of file +} -- Gitblit v1.9.3