知识大全 java正则匹配解析出时间
Posted 时间
篇首语:路漫漫其修远兮,吾将上下而求索。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 java正则匹配解析出时间相关的知识,希望对你有一定的参考价值。
java正则匹配解析出时间
package zhengze;
import java text ParseException;
import java text SimpleDateFormat;
import java util regex *;
import java util Date;
public class zhengze
public static void main(String[] args) throws ParseException
// String path =
// /user/sunflower/flume/msp/ / / /vortex pro hadoop ;
// String reg =
// ^\\\\d [ ] [ ] [ ]|[ ]\\\\d| [ ] [ ][ ]:[ ]\\\\d:[ ]\\\\d ;
// String checkValue = / ;
// String reg = ^\\\\d [ ]\\\\d [ ]\\\\d/[ ][ ]$ ;
//
// String reg =
// ^\\\\d [ ][ ] [ ][ ] [ ][ ]:[ ]\\\\d:[ ]\\\\d$ ;
//
// Pattern p = pile(reg)
// Matcher m = p matcher(checkValue)
// boolean b = m matches()
// if(b)
//
//
// System out println( 格式正确 )
//
// else
//
// System out println( 格式错误 )
//
String path = /string/string/string/ / /string/string ;
// Pattern pattern = pile( \\\\d [ ]\\\\d [ ]\\\\d/[ ]\\\\d )
// Matcher matcher = pattern matcher(path)
//
// if (matcher find())
// String src = matcher group()
// System out println(src)
// SimpleDateFormat sdf = new SimpleDateFormat( yyyy MM dd/hh )
// Date date = sdf parse(src)
// System out println(date)
//
// long t = date getTime() + * ;
//
// System out println(t)
//
//
Pattern pattern = pile( \\\\d [ ]\\\\d [ ]\\\\d/[ ]\\\\d )
Matcher matcher = pattern matcher(path)
Date datefile = null;
if (matcher find())
String src = matcher group()
System out println(src)
SimpleDateFormat df = new SimpleDateFormat( yyyy MM dd/hh )
try
datefile = df parse(src)
catch (ParseException e)
// TODO Auto generated catch block
e printStackTrace()
long readyTime = datefile getTime() + * ;
System out println(datefile)
System out println(datefile getTime())
System out println(readyTime)
Date d = new Date(readyTime)
System out println(d toString())
cha138/Article/program/Java/hx/201311/26307
相关参考