From 5bfcd30741d716cb46bb4540051c3bed65737189 Mon Sep 17 00:00:00 2001
From: chenjiahe <763432473@qq.com>
Date: 星期五, 16 十二月 2022 11:50:00 +0800
Subject: [PATCH] 新增时间算法

---
 src/main/java/com/hx/util/DateUtil.java |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/hx/util/DateUtil.java b/src/main/java/com/hx/util/DateUtil.java
index 617b78b..befbd61 100644
--- a/src/main/java/com/hx/util/DateUtil.java
+++ b/src/main/java/com/hx/util/DateUtil.java
@@ -603,6 +603,22 @@
         return sdf.format(calendar.getTime());
     }
 
+    /**
+     * 鑾峰彇褰撳墠骞寸殑寮�濮嬫椂闂�
+     * @param time 鏃堕棿
+     * @return 杩斿洖鏃堕棿 鏍煎紡yyyy-MM-dd 00:00:00
+     */
+    public static Date getYearStart(Date time) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(time);
+        calendar.set(Calendar.MONTH, 1);
+        calendar.set(Calendar.DAY_OF_MONTH, 1);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.SECOND, 0);
+        return calendar.getTime();
+    }
+
 
     /**
      * 鏃ユ湡2000-01-01鍙�2000-01-01 00:00:00
@@ -628,6 +644,18 @@
         calendar.set(Calendar.SECOND, 59);
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
         return sdf.format(calendar.getTime());
+    }
+
+    /**
+     * 鏃ユ湡2000-01-01鍙�2000-01-01 23:59:59
+     */
+    public static Date dayToEndDate(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.HOUR, 23);
+        calendar.set(Calendar.MINUTE, 59);
+        calendar.set(Calendar.SECOND, 59);
+        return calendar.getTime();
     }
 
     /**鑾峰彇鏈堜唤鐨勫ぉ鏁�
@@ -671,4 +699,19 @@
         calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
         return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
     }
+
+    /**褰撳ぉ澶氬皯鐐瑰墠
+     * @param date 鏃堕棿
+     * @param num 澶氬皯鐐瑰墠锛屼笉鍚綋鐐瑰墠锛�24灏忔椂鍒�
+     * @return 鏈堜唤鐨勫ぉ鏁�
+     */
+    public static boolean getFrontMinute(Date date,int num) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.set(Calendar.HOUR, num-1);
+        cal.set(Calendar.MINUTE, 59);
+        cal.set(Calendar.SECOND, 59);
+
+        return date.compareTo(cal.getTime()) < 1;
+    }
 }

--
Gitblit v1.8.0