Package javaapplication1; import Java. text. simpledateformat; import Java. util. date; import Java. util. regEx. pattern;/***** @ author yjmao * @ version v1.0.0 * @ date 2012-10-11 * @ deprecated start time and end time comparison (Regular Expression comparison) */public class checkdate {public static void main (string [] ARGs) {string starttime = "12:25:56"; string endtime = "12:25:55"; string error = checkdateflag (starttime, endtime ); System. err. println (error);} public static string checkdateflag (string starttime, string endtime) {stringbuilder year_mounth_date_hour_minute_second = new stringbuilder (); // [1-9] {1} [0-9] {3 }: matching year 1000-9999 year_mounth_date_hour_minute_second.append ("[1-9] {1} [0-9] {3 }"). append ("-"); // ([1-9] | [0] {1} [1-9] {1} | [1] {1} [0-2] {1 }) matched month: 1-12, 01-12, or year_mounth_date_hour_minute_second.append ("([1-9] | [0] {1} [1-9] {1} | [1] {1} [0-2] {1 })"). append ("-"); // ([1-9] | [0] {1} [1-9] {1} | [1-2] {1} [0-9] {1} | [3] {1} [0-1] {1 }) matching day: 1-31 or 01-31 year_mounth_date_hour_minute_second.append ("([1-9] | [0] {1} [1-9] {1} | [1-2] {1} [0 -9] {1} | [3] {1} [0-1] {1 }) "). append ("\ s *"); // ([0-9] | [0-1] {1} [0-9] {1} | [2] {1} [0-3] {1}): matching hour: 00-23 or 0-23 year_mounth_date_hour_minute_second.append ("([0-9] | [0-1] {1} [0-9] {1} | [2] {1} [0 -3] {1 }): "); // ([0-9] | [0-5] {1} [0-9] {1}): matching minutes: 00-59 or 0-59 year_mounth_date_hour_minute_second.append ("([0-9] | [0-5] {1} [0-9] {1 }):"); // ([0-9] | [0-5] {1} [0-9] {1}): matching seconds: 00-59 or 0-59 year_mounth_date_hour_minute_second.append ("([0-9] | [0-5] {1} [0-9] {1 })"); // matched string regtime = year_mounth_date_hour_minute_second.tostring (); stringbuilder errorinfo = new stringbuilder (); If (starttime. indexof ("/")! =-1) {starttime = starttime. Replace ("/", "-");} If (endtime. indexof ("/")! =-1) {endtime = endtime. replace ("/", "-");} pattern = pattern. compile (regtime); Boolean starttimeflag = pattern. matcher (starttime ). matches (); Boolean endtimeflag = pattern. matcher (endtime ). matches (); If (! Starttimeflag) {errorinfo. append ("Incorrect start time format! ");} If (! Endtimeflag) {errorinfo. append ("the end time format is incorrect! ");} Simpledateformat SDF = new simpledateformat (" yyyy-mm-dd hh: mm: SS "); Date startdate = NULL, enddate = NULL; try {startdate = SDF. parse (starttime); enddate = SDF. parse (endtime);} catch (exception e) {} If (startdate. after (enddate) {errorinfo. append ("the start time cannot be earlier than the end time! ") ;}Return errorinfo. tostring ();}}