public static String getDateTimeFromBDMFileName(String FileName) throws ParseException { //这里的FileName为全路径 File file=new File(FileName); String name=file.getName(); String[] arr=name.split("_"); if(arr.length==1){ System.out.println("BDM文件名格式异常,程序退出"); System.exit(0); } if(arr.length== 3){ name=arr[2]; }else { System.out.println("BDM文件名格式异常,程序退出"); System.exit(0); } String regex="[0-9]{8}B[0-9]{6}"; Pattern pattern=Pattern.compile(regex); Matcher matcher=pattern.matcher(name); if(matcher.find()){ String dateStr=matcher.group(0); DateFormat df=new SimpleDateFormat("yyyyMMdd'B'HHmmss"); DateFormat df2=new SimpleDateFormat("yyyyMMdd'T'HHmmss"); Date d=df.parse(dateStr); long time=d.getTime()-8*60*60*1000;//北京时间转化成格林尼治时间 Date d2=new Date(time); return df2.format(d2); }else{ System.out.println("BDM文件名格式异常,程序退出"); System.exit(0); return "20190101T000000"; } }
JAVA 通过正则匹配获取文件名中的事件信息
最新推荐文章于 2021-02-18 10:27:52 发布