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 | 63 ++++++++++++++++++++++++++++++- 1 files changed, 61 insertions(+), 2 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 ce16371..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,14 +2,46 @@ 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 str = "PACK.OP360.ModuleSNCode1"; - System.out.println(str.charAt(str.length()-1)); + 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){ @@ -79,4 +111,31 @@ 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