From 2e81e44c7dc4945b9d1db55bf0357e4c79d59500 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期二, 04 七月 2023 16:15:42 +0800
Subject: [PATCH] websocket推送ptz增加剩余秒数

---
 ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java |  105 ++++++++++++++++++++++++----------------------------
 1 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
index 00f2c57..4a46064 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
@@ -9,15 +9,15 @@
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.util.Date;
+
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 /**
  * 鏃堕棿宸ュ叿绫�
- * 
+ *
  * @author ruoyi
  */
-public class DateUtils extends org.apache.commons.lang3.time.DateUtils
-{
+public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
     public static String YYYY = "yyyy";
 
     public static String YYYY_MM = "yyyy-MM";
@@ -31,65 +31,54 @@
     public static String HH_MM_SS = "HH:mm:ss";
 
     private static String[] parsePatterns = {
-            "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", 
+            "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
             "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
             "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
 
     /**
      * 鑾峰彇褰撳墠Date鍨嬫棩鏈�
-     * 
+     *
      * @return Date() 褰撳墠鏃ユ湡
      */
-    public static Date getNowDate()
-    {
+    public static Date getNowDate() {
         return new Date();
     }
 
     /**
      * 鑾峰彇褰撳墠鏃ユ湡, 榛樿鏍煎紡涓簓yyy-MM-dd
-     * 
+     *
      * @return String
      */
-    public static String getDate()
-    {
+    public static String getDate() {
         return dateTimeNow(YYYY_MM_DD);
     }
 
-    public static final String getTime()
-    {
+    public static final String getTime() {
         return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
     }
-    public static final String dateTimeNow()
-    {
+    public static final String dateTimeNow() {
         return dateTimeNow(YYYYMMDDHHMMSS);
     }
     public static final String dateTimeNowMS()
     {
         return dateTimeNow(YYYY_MM_DD_HH_MM_SS_MS);
     }
-    public static final String dateTimeNow(final String format)
-    {
+    public static final String dateTimeNow(final String format) {
         return parseDateToStr(format, new Date());
     }
 
-    public static final String dateTime(final Date date)
-    {
+    public static final String dateTime(final Date date) {
         return parseDateToStr(YYYY_MM_DD, date);
     }
 
-    public static final String parseDateToStr(final String format, final Date date)
-    {
+    public static final String parseDateToStr(final String format, final Date date) {
         return new SimpleDateFormat(format).format(date);
     }
 
-    public static final Date dateTime(final String format, final String ts)
-    {
-        try
-        {
+    public static final Date dateTime(final String format, final String ts) {
+        try {
             return new SimpleDateFormat(format).parse(ts);
-        }
-        catch (ParseException e)
-        {
+        } catch (ParseException e) {
             throw new RuntimeException(e);
         }
     }
@@ -97,8 +86,7 @@
     /**
      * 鏃ユ湡璺緞 鍗冲勾/鏈�/鏃� 濡�2018/08/08
      */
-    public static final String datePath()
-    {
+    public static final String datePath() {
         Date now = new Date();
         return DateFormatUtils.format(now, "yyyy/MM/dd");
     }
@@ -106,8 +94,7 @@
     /**
      * 鏃ユ湡璺緞 鍗冲勾/鏈�/鏃� 濡�20180808
      */
-    public static final String dateTime()
-    {
+    public static final String dateTime() {
         Date now = new Date();
         return DateFormatUtils.format(now, "yyyyMMdd");
     }
@@ -115,18 +102,13 @@
     /**
      * 鏃ユ湡鍨嬪瓧绗︿覆杞寲涓烘棩鏈� 鏍煎紡
      */
-    public static Date parseDate(Object str)
-    {
-        if (str == null)
-        {
+    public static Date parseDate(Object str) {
+        if (str == null) {
             return null;
         }
-        try
-        {
+        try {
             return parseDate(str.toString(), parsePatterns);
-        }
-        catch (ParseException e)
-        {
+        } catch (ParseException e) {
             return null;
         }
     }
@@ -134,8 +116,7 @@
     /**
      * 鑾峰彇鏈嶅姟鍣ㄥ惎鍔ㄦ椂闂�
      */
-    public static Date getServerStartDate()
-    {
+    public static Date getServerStartDate() {
         long time = ManagementFactory.getRuntimeMXBean().getStartTime();
         return new Date(time);
     }
@@ -143,16 +124,14 @@
     /**
      * 璁$畻鐩稿樊澶╂暟
      */
-    public static int differentDaysByMillisecond(Date date1, Date date2)
-    {
+    public static int differentDaysByMillisecond(Date date1, Date date2) {
         return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
     }
 
     /**
      * 璁$畻涓や釜鏃堕棿宸�
      */
-    public static String getDatePoor(Date endDate, Date nowDate)
-    {
+    public static String getDatePoor(Date endDate, Date nowDate) {
         long nd = 1000 * 24 * 60 * 60;
         long nh = 1000 * 60 * 60;
         long nm = 1000 * 60;
@@ -173,8 +152,7 @@
     /**
      * 澧炲姞 LocalDateTime ==> Date
      */
-    public static Date toDate(LocalDateTime temporalAccessor)
-    {
+    public static Date toDate(LocalDateTime temporalAccessor) {
         ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
@@ -182,31 +160,29 @@
     /**
      * 澧炲姞 LocalDate ==> Date
      */
-    public static Date toDate(LocalDate temporalAccessor)
-    {
+    public static Date toDate(LocalDate temporalAccessor) {
         LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
         ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
 
     /*鍒ゆ柇鏃堕棿鏄惁鍦ㄦ椂闂村唴*/
-    public static boolean TimeCompare(String startT,String endT)
-    {
+    public static boolean TimeCompare(String startT, String endT) {
         LocalTime startTime = LocalTime.parse(startT); // 寮�濮嬫椂闂�
         LocalTime endTime = LocalTime.parse(endT); // 缁撴潫鏃堕棿
         LocalTime currentTime = LocalTime.now(); // 褰撳墠鏃堕棿
         // 鍒ゆ柇褰撳墠鏃堕棿鏄惁鍦ㄦ椂闂村尯闂村唴
         if (currentTime.isAfter(startTime) && currentTime.isBefore(endTime)) {
-           // System.out.println("褰撳墠鏃堕棿鍦ㄦ椂闂村尯闂村唴");
+            // System.out.println("褰撳墠鏃堕棿鍦ㄦ椂闂村尯闂村唴");
             return true;
         } else {
-           // System.out.println("褰撳墠鏃堕棿涓嶅湪鏃堕棿鍖洪棿鍐�");
+            // System.out.println("褰撳墠鏃堕棿涓嶅湪鏃堕棿鍖洪棿鍐�");
             return false;
         }
     }
-    public static boolean TimeCompare(Date startT,Date endT)
-    {
-        Date current=new Date();
+
+    public static boolean TimeCompare(Date startT, Date endT) {
+        Date current = new Date();
         // 鍒ゆ柇褰撳墠鏃堕棿鏄惁鍦ㄦ椂闂村尯闂村唴
         if (current.after(startT) && current.before(endT)) {
             // System.out.println("褰撳墠鏃堕棿鍦ㄦ椂闂村尯闂村唴");
@@ -216,4 +192,19 @@
             return false;
         }
     }
+
+    /**
+     * 璁$畻涓や釜鏃堕棿绉掔殑宸�
+     */
+    public static long getSecDatePoor(Date endDate, Date nowDate) {
+        long nd = 1000 * 24 * 60 * 60;
+        long nh = 1000 * 60 * 60;
+        long nm = 1000 * 60;
+        long ns = 1000;
+        // 鑾峰緱涓や釜鏃堕棿鐨勬绉掓椂闂村樊寮�
+        long diff = endDate.getTime() - nowDate.getTime();
+        // 璁$畻宸灏戠//杈撳嚭缁撴灉
+        long sec = diff/ ns;
+        return sec;
+    }
 }

--
Gitblit v1.9.3