比較兩個日期進(jìn)行訂購。
public int compareTo(Date anotherDate)
anotherDate - 要比較的日期。
返回值 - 值 0 (如果參數(shù)Date等于此日期) 如果此日期在Date參數(shù)之前,則小于 0 的值; 如果此日期位于Date參數(shù)之后,則該值大于 0 。
下面是一個使用這個方法的例子 -
class Example { static void main(String[] args) { Date olddate = new Date("05/11/2015"); Date newdate = new Date("05/11/2015"); Date latestdate = new Date(); System.out.println(olddate.compareTo(newdate)); System.out.println(latestdate.compareTo(newdate)); } }
當(dāng)我們運(yùn)行上面的程序,我們將得到以下結(jié)果 -
0 1
更多建議: