用compareTo(Date anotherDate),查看源码,具体方法如下:
public int compareTo(Date anotherDate) {
long thisTime = getMillisOf(this);
long anotherTime = getMillisOf(anotherDate);
return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
}
描述:比较两个日期;
参数:日期是Date类型;
返回值:整型,结果是:大于返回1,等于返回0,小于返回-1。
注:参数必须是Date类型的日期进行比较返回值才是确定的1、0、-1。