Die Veröffentlichungszeit verschiedener Formate auf der Webseite wird extrahiert und die Veröffentlichungszeit wird im regulären "yyyy-mm-dd HH: MM: SS" -Format ausgedrückt. Sie können nur versuchen, die Genauigkeit zu verfolgen, aber da das Format der Netzwerkfreigabemaßzeit sehr flexibel ist, kann es nicht 100% korrekt sein.
Paket whu.extract.pubtime.core; Import Java.util.ArrayList; Import Java.util.Calendar; Import Java.util.Collections; Import Java.util.List; Import Java.util.regex.matcher; Import Java.util.Regex.pattern; import whu.utils.timeUtil; /*** Erstellt am 13. März 2014 um 14:49:05 Uhr* @Description die Veröffentlichungszeit der Webseite erhalten "([-|/| _] {1} 20 // d {6})"; /** stellt ein Datum dar, das durch-oder/mit einem Jahr, Monat und Datum getrennt ist, z. "([-|/| _] {1} 20 // d {2} [-|/| _] {1} // d {1,2})"; /** zeigt an, dass Daten von - OR/, nur Jahr und Monat getrennt sind, z. "([-|/| _] {1} 20 // d {2} [-|/| _] {1} // d {1,2})"; privat statischer Kalender current = calendar.getInstance (); / ** korrekte Formatierzeit regulärer Ausdruck*/ private statische String RightTimereg = "^((// d {2} (([02468] [048]) | ([13579] [26]) [//-/// s]? (((0? [13578]) | (1 [02]) [//-///// s]? ((0? [1-9]) | ([1-2] [0-9]) | (3 [01])) | ((0? [469]) | ( 11)) [//-//// s]? ((0? [1-9]) | ([1-2] [0-9]) | (30)) | (0? 2 [//-//// S]? ((0? [ 1-9]) | ([1-2] [0-9]))))) | (// d {2} (([02468] [1235679]) | ([13579] [01345789 ])) [//-///// s]? ((((0? [13578]) | (1 [02]) [//-///// S]? [0-9]) | (3 [01]))) | ((0? [469]) | (11)) [//-//// s]? ((0? [1-9]) | ([1-2] [0-9]] ) | (30)) | (0? 2 [//-/// s]? ((0? [1-9]) | (1 [0-9]) | (2 [0-8])))))))))))))))? $ "; / ** * @param url * @param urlContent * @return */ public static String getPuBTimeVarious (String -URL, String urlContent) {String pubtime = getPubtimeFromurl (URL); // Nicht im Link, Matching if (pubtime == null) {if (urlContent! = Null &&! } Return Pubime; } / ** Die Veröffentlichungszeit aus der URL extrahieren und yyyy-mm-dd hh: mm: ss-formatted string zurück zurückgeben Matcher M_WOOLE = p_Whole.Matcher (URL); if (m_whole.find (0) && m_whole.groupCount ()> 0) {String time = m_whole.group (0); time = time.substring (1, time.length ()); // Jeder Schritt kann die aktuelle Zeit nicht überschreiten, wenn (current.comPareto (timeutil.strtocalendar (Zeit, "yyyymmdd")> = 0) {Return Time.Substring (0,4)+"-"+time.substring (4,6)+"-"+time.substring (6,8)+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+"+" }} P_WOOLE = NULL; M_WOOLE = NULL; Muster p_sep = muster.comPile (url_reg_sep_ymd); Matcher M_SEP = P_SEP.Matcher (URL); if (m_sep.find (0) && m_sep.groupCount ()> 0) {String time = m_sep.group (0); time = time.substring (1, time.length ()); String [] Seg = time.Split ("[-|/| _] {1}"); Kalender thetime = calendar.getInstance (); thetime.set (Calendar.year, Integer.ParseInt (Seg [0])); thetime.set (Calendar.month, Integer.ParseInt (Seg [1])); thetime.set (Calendar.day_of_month, Integer.ParseInt (Seg [2])); if (current.comPareto (thetime)> = 0) {return SEG [0]+"-"+SEG [1]+"-"+SEG [2]+""+"00:00:00"; }} p_sep = null; m_sep = null; MUSTER P_SEP_YM = MUSTENTECOMPILE.COMPILE (url_reg_sep_ym); Matcher M_SEP_YM = P_SEP_YM.MATCHER (URL); if (m_sep_ym.find (0) && m_sep_ym.groupCount ()> 0) {String time = m_sep_ym.group (0); time = time.substring (1, time.length ()); Kalender thetime = calendar.getInstance (); String [] Seg = time.Split ("[-|/| _] {1}"); thetime.set (Calendar.year, Integer.ParseInt (Seg [0])); thetime.set (Calendar.month, Integer.ParseInt (Seg [1])); thetime.set (calendar.day_of_month, 1); if (current.comPareto (thetime)> = 0) {return SEG [0]+"-"+SEG [1]+"-"+"+" 01 "+" "+" 00:00:00 ";}} return null;} /** Extrahieren Sie die Veröffentlichungszeit aus dem Webpage-Quellcode. 2013-12-19 15:48:33 oder 2013-12-19 oder 2012/3/05* @param Text String extrahiert* @Return-Datum* @Author: Oschina* @CreateTime: Januar 21, 2013*/public static StringPagedate (String text) {Boolean contentsShms = false-datestrate; = NULL; Muster p_detail = muster.comPile ("(20 // d {2} [-/] // d {1,2} [-/] // d {1,2} // d {1,2}: // d {1,2} monat // d {1,2} | Muster.case_inemsitiv | muster.multiline); Muster.case_inemsitiv | muster.multilin); // Matcher Matcher = P.Matcher (datESTR); Matcher Matcher_detail = p_detail.matcher (datester); if (! (matcher_detail.find (0) && matcher_detail.groupCount ()> = 1)) {matcher_detail = p.matcher (datester); contentShs = true; } else matcher_detail = p_detail.matcher (datESTR); if (matcher_detail.find () && matcher_detail.groupCount ()> = 1) {matches = new ArrayList (); für (int i = 1; i <= matcher_detail.groupCount (); i ++) {String temp = matcher_detail.group (i); Matches.add (temp); }} else {matches = collectionss.Empty_List; } if (matches.size ()> 0) {für (int i = 0; i <matches.size (); i ++) {String pubtime = masce.get (i) .toString (). trim (); // Nehmen Sie den ersten Wert Pubtime = Pubtime.replace ("/", "-"). Ersetzen ("Jahr", "-"). Ersetzen ("Monat", "-"). Ersetzen ("Tag", "-"); if (current.comPareto (timeutil.strtocalendar (pubime, "yyyy-mm-dd"))> = 0) {if (contentsSHMS) Pubime+= ""+"00:00:00"; if (pubtime.matches (rightTimereg)) {return pubtime; }}}} else {return null; }} catch (Ausnahme e) {return null; } return null; }}Das obige dreht sich alles um diesen Artikel. Ich hoffe, dass es für alle hilfreich sein wird, Java -Programme zu lernen.