日期:2014-05-18  浏览次数:20661 次

求个正则表达式
http://www.sina.com.cn   2007年04月19日05:58

本报4月18日讯今年3月,侯马市公安局在两天内
突击提拔了92名中层干部

如何从这两段文字中提取时间?

------解决方案--------------------
public static void main(String[] args) throws ParseException {
String news = "http://www.sina.com.cn 2007年04月19日05:58 ...... ";
String timeStr = news.replaceFirst( ".*(\\d{4}年\\d{2}月\\d{2}日\\d{2}:\\d{2}).* ", "$1 ");
SimpleDateFormat sf = new SimpleDateFormat( "yyyy年MM月dd日HH:mm ");
Date date = sf.parse(timeStr);
System.out.println(date);
}
------解决方案--------------------
split();
------解决方案--------------------
split 或者用chatAT

------解决方案--------------------
public static void main(String[] args) throws ParseException {
String news = "http://www.sina.com.cn 2007年04月19日05:58 ...... ";
String timeStr = news.replaceFirst( ".*(\\d{4}年\\d{2}月\\d{2}日\\d{2}:\\d{2}).* ", "$1 ");
SimpleDateFormat sf = new SimpleDateFormat( "yyyy年MM月dd日HH:mm ");
Date date = sf.parse(timeStr);
System.out.println(timeStr);
System.out.println(date);
}