第一种直接用字符串类的compareTo方法:
-
String t1="20131011";
-
String t2="20131030";
-
int result = t1.compareTo(t2);
第二种是把这个日期字符串转换成long:
-
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
-
Date d1 = sdf.parse(t1);
-
Date d2 = sdf.parse(t2);
-
long result = d1.getTime()-d2.getTime();
第三种是把日期字符串转换成整形int:
-
int int1 = Integer.parseInt(t1);
-
int int2 = Integer.parseInt(t2);
-
int result = int1-int2;
注:result大于0,则t1>t2;
result等于0,则t1=t2;
result小于0,则t1<t2;