| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package com.mes.util;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.concurrent.TimeUnit;
- public class CommonUtils {
- public static String getDateByBefor(int ngTime) {
- try{
- Calendar beforeTime = Calendar.getInstance();
- beforeTime.add(Calendar.MINUTE, -ngTime);// 5分钟之前的时间
- Date beforeD = beforeTime.getTime();
- String before5 = new SimpleDateFormat("yyyyMMddHHmmss").format(beforeD);
- return before5;
- }catch (Exception e){
- return null;
- }
- }
- public static long jsSecond(String timeStr1,String timeStr2){
- // 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);
- return seconds;
- } catch (Exception e) {
- e.printStackTrace();
- return 0;
- }
- }
- /**
- * 判段工件码是否符合要求
- * @param sn 工件码
- * @param spec 规格
- * @param specStart 规格开始位置
- * @param length 码长度
- * @return
- */
- public static Boolean checkSnByModel(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;
- }
- }
|