熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

java正則匹配解析出時間

2013-11-23 19:07:38  來源: Java核心技術 

  java正則匹配解析出時間

  package zhengze;

  import javatextParseException;

  import javatextSimpleDateFormat;

  import javautilregex*;

  import javautilDate;

  public class zhengze {

  public static void main(String[] args) throws ParseException {

  // String path =

  // /user/sunflower/flume/msp////vortexprohadoop;

  // String reg =

  // ^\\d{}[][][]|[]\\d|[] [][]:[]\\d:[]\\d;

  // String checkValue = /;

  // String reg = ^\\d{}[]\\d[]\\d/[][]$;

  //

  // String reg =

  // ^\\d{}[][][][] [][]:[]\\d:[]\\d$;

  //

  // Pattern p = pile(reg)

  // Matcher m = pmatcher(checkValue)

  // boolean b = mmatches()

  // if(b)

  // {

  //

  // Systemoutprintln(格式正確

  // }

  // else

  // {

  // Systemoutprintln(格式錯誤

  // }

  String path = /string/string/string///string/string;

  //    Pattern pattern = pile(\\d{}[]\\d[]\\d/[]\\d

  //    Matcher matcher = patternmatcher(path)

  //

  //    if (matcherfind()) {

  //      String src = matchergroup()

  //      Systemoutprintln(src)

  //      SimpleDateFormat sdf = new SimpleDateFormat(yyyyMMdd/hh

  //      Date date = sdfparse(src)

  //      Systemoutprintln(date)

  //

  //      long t = dategetTime() + *;

  //

  //      Systemoutprintln(t)

  //

  //    }

  Pattern pattern = pile(\\d{}[]\\d[]\\d/[]\\d

  Matcher matcher = patternmatcher(path)

  Date datefile = null;

  if (matcherfind()) {

  String src = matchergroup()

  Systemoutprintln(src)

  SimpleDateFormat df = new SimpleDateFormat(yyyyMMdd/hh

  try {

  datefile = dfparse(src)

  } catch (ParseException e) {

  // TODO Autogenerated catch block

  eprintStackTrace()

  }

  }

  long readyTime = datefilegetTime() + *;

  Systemoutprintln(datefile)

  Systemoutprintln(datefilegetTime())

  Systemoutprintln(readyTime)

  Date d = new Date(readyTime)

  Systemoutprintln(dtoString())

  }

  }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26307.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.