try{ date.valueof(string astring);}catch(exception ex){ system.err.println("the format of string is not correct");}
或者
public class forother { public static void main(string[] args){ simpledateformat s=new simpledateformat("yyyy-mm-dd hh:mm:ss"); string ooo="2005-02-18 15:39:15"; string ppp="2005-02-01 15:25:15"; try{ date tt=s.parse(ooo); date yy=s.parse(ppp); long aa; if(tt.gettime()>yy.gettime()) aa=tt.gettime()-yy.gettime(); else aa=yy.gettime()-tt.gettime(); long date=aa/1000/60/60/24; system.out.println("***"); system.out.println("hahahha"+date); system.out.println("*******"); }catch(exception e){ } }}
