Comparison of java Implementation Time and java Implementation Time
It is very common to compare the time size and convert the String type time to the Date class. The following is a tool method.
Public class Test {public static void main (String [] args) {// TODO Auto-generated method stub String sTime = "2015-07-13"; String fTime = "2015-07-15"; System. out. println (compareDate (stringToDate (fTime), stringToDate (sTime);} public static Date stringToDate (String dateString) {return stringToDate (dateString, "yyyy-MM-dd");} public static Date stringToDate (String dateText, String format) {DateFormat df = null; try {if (format = null) {df = new SimpleDateFormat ();} else {df = new SimpleDateFormat (format);} df. setLenient (false); return df. parse (dateText);} catch (ParseException e) {return null ;}} /*** time judgment ** @ param firstTime * @ param secondTime * @ return the first time is earlier than the second time-1; the first time is equal to the second time 0; 1 */public static int compareDate (Date firstTime, Date secondTime) {long lFirstTime = firstTime. getTime (); long lsecondTime = secondTime. getTime (); if (lFirstTime <lsecondTime) {return-1 ;}else if (lFirstTime> lsecondTime) {return 1 ;}else {return 0 ;}}}