同学Java API中java.util.Date类中有一个compareTo的方法,给你拷贝到这里了:
public int compareTo(Date anotherDate)
Compares two Dates for ordering.
Specified by:compareTo in interface Comparable<Date>Parameters:anotherDate - the Date to be compared.
Returns:the value 0 if the argument Date is equal to this Date; a value less than 0 if this Date is before the Date argument; and a value greater than 0 if this Date is after the Date argument.Throws:NullPointerException - if anotherDate is null.Since:1.2
主要看的是最后一段,我给你翻译一下:
返回值:如果返回值是0 的话说明这两个日期相等,如果返回值小于零的话就说明这个日期在anotherDate之前,也就是比anotherDate大,如果大于0说明这个日期在anotherDate之后,也就说这个日期比anotherDate小。明白了吗? |