标签:
方式一:
String time1="2015-05-06 08:08:08";
String time2="2015-05-06 08:06:08";
try {
SimpleDateFormat foramt=new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
Date mDate1=foramt.parse(time1);
Date mDate2=foramt.parse(time2);
int result=
mDate1.compareTo(mDate2);
} catch (ParseException e) {
e.printStackTrace();
}
方式二:
String time1="2015-05-06 08:08:08";
String time2="2015-05-06 08:06:08";
try {
SimpleDateFormat foramt=new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
Date mDate1=foramt.parse(time1);
Date mDate2=foramt.parse(time2);
long result=mDate1.getTime()-mDate2.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
方式三:
String time1="2015-05-06 08:08:08";
String time2="2015-05-06 08:06:08";
try {
SimpleDateFormat foramt=new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
Date mDate1=foramt.parse(time1);
Date mDate2=foramt.parse(time2);
boolean result=mDate1.after(mDate2);
} catch (ParseException e) {
e.printStackTrace();
}
标签:
原文地址:http://blog.csdn.net/luo446718254/article/details/45891809