package com.jeesite.modules; import com.alibaba.fastjson.JSONObject; import okhttp3.*; import java.io.IOException; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Map; import java.util.concurrent.TimeUnit; public class Test { public static void main(String[] args) { String sn = "000020015308-0100101425070500044"; String ss = sn.substring(21,27); System.out.println(ss); // String timeStr1 = "2023-01-01 12:10:00"; // String timeStr2 = "2023-01-01 12:05:00"; // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // try { // Date date1 = sdf.parse(timeStr1); // Date date2 = sdf.parse(timeStr2); // long diffInMillies = Math.abs(date2.getTime() - date1.getTime()); // long seconds = TimeUnit.MILLISECONDS.toSeconds(diffInMillies); // System.out.println("Time difference in seconds: " + seconds); // } catch (Exception e) { // e.printStackTrace(); // } // // 获取当前日期 // LocalDate today = LocalDate.now(); // // 获取明天的日期 // LocalDate tomorrow = today.plusDays(1); // // // 定义日期格式 // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // // // 格式化并打印今天的日期 // String formattedToday = today.format(formatter); // System.out.println("今天: " + formattedToday); // // // 格式化并打印明天的日期 // String formattedTomorrow = tomorrow.format(formatter); // System.out.println("明天: " + formattedTomorrow); // String uAUnit1 = "uA"; // String mAUnit2 = "mA"; // String dl = "008.7 uA"; // Float dlval = Float.valueOf("0"); // boolean dlresult2 = dl.contains(mAUnit2); // if(dlresult2){ // dlval = Float.valueOf(dl.replaceAll("[^0-9.]", "")); // } // boolean dlresult1 = dl.contains(mAUnit2); // if(dlresult1){ // dlval = Float.valueOf(dl.replaceAll("[^0-9.]", ""))/1000; // } // // DecimalFormat decimalFormat = new DecimalFormat("#.###"); // String dlformattedNumber = decimalFormat.format(dlval); // System.out.println(dlformattedNumber); // String valueWithUnit = "3.068Gohm"; // // 使用正则表达式匹配所有非数字字符,并替换为空字符串 // String valueOnly = valueWithUnit.replaceAll("[^0-9.]", ""); // System.out.println(valueOnly); // 输出: 100 // String sn = "000020015308-0100101425040800275"; // String spec = "5308"; // Integer specStart = 9; // Integer length = 32; // Boolean ret = checkSn(sn, spec, specStart, length); // System.out.println(ret); } public static Boolean checkSn(String sn, String spec,Integer specStart, Integer length) { if(sn.length()!=length){ return false; } Integer start=specStart - 1; Integer end=start + spec.length(); if(length > end){ String newSpec = sn.substring(start,end); if(newSpec.equals(spec)){ return true; } } return false; } }