Test.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.jeesite.modules;
  2. import com.alibaba.fastjson.JSONObject;
  3. import okhttp3.*;
  4. import java.io.IOException;
  5. import java.text.DecimalFormat;
  6. import java.text.SimpleDateFormat;
  7. import java.time.Duration;
  8. import java.time.Instant;
  9. import java.time.LocalDate;
  10. import java.time.format.DateTimeFormatter;
  11. import java.util.Date;
  12. import java.util.Map;
  13. import java.util.concurrent.TimeUnit;
  14. public class Test {
  15. public static void main(String[] args) {
  16. String sn = "000020015308-0100101425070500044";
  17. String ss = sn.substring(21,27);
  18. System.out.println(ss);
  19. // String timeStr1 = "2023-01-01 12:10:00";
  20. // String timeStr2 = "2023-01-01 12:05:00";
  21. // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  22. // try {
  23. // Date date1 = sdf.parse(timeStr1);
  24. // Date date2 = sdf.parse(timeStr2);
  25. // long diffInMillies = Math.abs(date2.getTime() - date1.getTime());
  26. // long seconds = TimeUnit.MILLISECONDS.toSeconds(diffInMillies);
  27. // System.out.println("Time difference in seconds: " + seconds);
  28. // } catch (Exception e) {
  29. // e.printStackTrace();
  30. // }
  31. // // 获取当前日期
  32. // LocalDate today = LocalDate.now();
  33. // // 获取明天的日期
  34. // LocalDate tomorrow = today.plusDays(1);
  35. //
  36. // // 定义日期格式
  37. // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  38. //
  39. // // 格式化并打印今天的日期
  40. // String formattedToday = today.format(formatter);
  41. // System.out.println("今天: " + formattedToday);
  42. //
  43. // // 格式化并打印明天的日期
  44. // String formattedTomorrow = tomorrow.format(formatter);
  45. // System.out.println("明天: " + formattedTomorrow);
  46. // String uAUnit1 = "uA";
  47. // String mAUnit2 = "mA";
  48. // String dl = "008.7 uA";
  49. // Float dlval = Float.valueOf("0");
  50. // boolean dlresult2 = dl.contains(mAUnit2);
  51. // if(dlresult2){
  52. // dlval = Float.valueOf(dl.replaceAll("[^0-9.]", ""));
  53. // }
  54. // boolean dlresult1 = dl.contains(mAUnit2);
  55. // if(dlresult1){
  56. // dlval = Float.valueOf(dl.replaceAll("[^0-9.]", ""))/1000;
  57. // }
  58. //
  59. // DecimalFormat decimalFormat = new DecimalFormat("#.###");
  60. // String dlformattedNumber = decimalFormat.format(dlval);
  61. // System.out.println(dlformattedNumber);
  62. // String valueWithUnit = "3.068Gohm";
  63. // // 使用正则表达式匹配所有非数字字符,并替换为空字符串
  64. // String valueOnly = valueWithUnit.replaceAll("[^0-9.]", "");
  65. // System.out.println(valueOnly); // 输出: 100
  66. // String sn = "000020015308-0100101425040800275";
  67. // String spec = "5308";
  68. // Integer specStart = 9;
  69. // Integer length = 32;
  70. // Boolean ret = checkSn(sn, spec, specStart, length);
  71. // System.out.println(ret);
  72. }
  73. public static Boolean checkSn(String sn, String spec,Integer specStart, Integer length) {
  74. if(sn.length()!=length){
  75. return false;
  76. }
  77. Integer start=specStart - 1;
  78. Integer end=start + spec.length();
  79. if(length > end){
  80. String newSpec = sn.substring(start,end);
  81. if(newSpec.equals(spec)){
  82. return true;
  83. }
  84. }
  85. return false;
  86. }
  87. }