From 6d313a4a6f9f9d7ea65ec50ab0d4491e595edb97 Mon Sep 17 00:00:00 2001
From: admin <15939171744@163.com>
Date: 星期二, 15 十月 2024 09:47:26 +0800
Subject: [PATCH] -打印bug修改

---
 jcdm-main/src/main/java/com/jcdm/main/plcserver/util/TimeUtil.java |   87 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/util/TimeUtil.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/util/TimeUtil.java
index ff32fe8..97269cc 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/util/TimeUtil.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/util/TimeUtil.java
@@ -2,11 +2,48 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 public class TimeUtil {
+    public static void main(String[] args) {
+        String dateString = "Tue May 14 18:25:18 CST 2024";
+//        System.out.println(test(dateString));
+//        String str = "OP330";
+//        System.out.println(str.substring(0,5));
+//        String tightenData = "[9.077463,12.0,OK,OK]";
+//        tightenData = tightenData.replace("[", "").replace("]", "").replace(" ", "");
+//        String[] tightenDataParts = tightenData.split(",");
+//        for (int i = 0; i < tightenDataParts.length; i++) {
+//            System.out.println(tightenDataParts[i]);
+//        }
+        String originalString = "[3.6,7.8,OK,OK]";
+        String modifiedString = originalString.replaceFirst("OK", "NG");
+        System.out.println(modifiedString); // 杈撳嚭: [3.6,7.8,NG,OK]
+//        System.out.println(isNumberInRange(7.7, 7.5, 8.5));
+//        System.out.println(test( stringProcessing("DateTime{utcTime=133601559184960000, javaDate=Tue May 14 18:25:18 CST 2024}")));
+    }
+
+    public static String replaceNumber(String input) {
+        String regex = ",(\\d+),";
+        String replacement = ",NG,";
+
+        Pattern pattern = Pattern.compile(regex);
+        Matcher matcher = pattern.matcher(input);
+
+        return matcher.replaceAll(replacement);
+    }
+
+    // 妫�鏌ヤ竴涓暟鏄惁鍦ㄤ袱涓暟瀹氫箟鐨勫尯闂村唴锛堜笉鍖呭惈杈圭晫锛�
+    public static boolean isNumberInRange(Double number, Double start, Double end) {
+        return number >= start && number <= end;
+    }
+
     public static String stringProcessing(String dateTimeStr){
         String result = "";
         // 鎵惧埌 "javaDate=" 鐨勪綅缃�
@@ -51,4 +88,54 @@
         }
         return result;
     }
+
+    public static String getYyyyDdMm(String inputDate){
+        String outputPattern = "yyyy-MM-dd HH:mm:ss";
+
+        // 瀹氫箟涓�涓В鏋愬櫒锛岀敤浜庡拷鐣ユ椂鍖猴紙浠呬綔涓虹ず渚嬶紝鍙兘闇�瑕佽皟鏁翠互澶勭悊涓嶅悓鐨勮緭鍏ワ級
+        SimpleDateFormat parser = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
+        parser.setLenient(false); // 璁剧疆涓嶅鏉撅紝浠ヤ弗鏍煎尮閰嶆牸寮�
+
+        // 瑙f瀽鏃ユ湡瀛楃涓�
+        Date date = null;
+        try {
+            date = parser.parse(inputDate);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+
+        // 瀹氫箟涓�涓牸寮忓寲鍣紝鐢ㄤ簬杈撳嚭鎵�闇�鐨勬牸寮�
+        SimpleDateFormat formatter = new SimpleDateFormat(outputPattern);
+
+        // 鏍煎紡鍖栨棩鏈�
+        String outputDate = formatter.format(date);
+        return outputDate;
+    }
+
+    public static String test(String param){
+        String str = "";
+        // 鍒涘缓涓�涓猄impleDateFormat瀵硅薄鏉ヨВ鏋愯緭鍏ョ殑鏃ユ湡瀛楃涓诧紙鍋囪CST涓轰腑鍥芥爣鍑嗘椂闂达級
+        SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
+        inputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); // 璁剧疆涓轰腑鍥芥椂鍖�
+
+        Date date = null;
+        try {
+            date = inputFormat.parse(param);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+
+        // 鍒涘缓涓�涓猄impleDateFormat瀵硅薄鏉ユ牸寮忓寲鏃ユ湡涓篣TC鏃堕棿
+        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        outputFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // 璁剧疆涓篣TC鏃跺尯
+
+        // 鏍煎紡鍖栨棩鏈�
+        if (date != null) {
+            str = outputFormat.format(date);
+        }
+        return str;
+    }
+
+
+
 }

--
Gitblit v1.9.3