Java code
Import java. text. ParseException;
Import java. text. SimpleDateFormat;
Import java. util. Calendar;
Import java. util. Date;
Public class {
Public static void main (String [] args) throws ParseException {
Date d1 = Calendar. getInstance (). getTime ();
String s1 = new SimpleDateFormat ("yyyy" + "-" + "MM" + "-" + "dd HH" + ":" + "mm" + ": "+" ss "). format (d1 );
System. out. println ("s1 =" + stb1 );
String time = "14:42:43 ";
SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");
Date dd = sdf. parse (time. toString ());
String ss = new SimpleDateFormat ("yyyy" + "-" + "MM" + "-" + "dd HH" + ":" + "mm" + ": "+" ss "). format (dd );
System. out. println ("ss =" + ss );
Int I = d1.compareTo (dd );
If (I <0 ){
System. out. println ("d1 earlier ");
} Else if (I = 0 ){
System. out. println ("Same as d1 ");
} Else {
System. out. println ("dd earlier ");
}
}
}
Author: tbwshc