2014-11-03 8 views

답변

3

java.util.Date를 언급하는 경우 date1.getTime() < date2.getTime()을 수행하십시오. 긴 값의 간단한 비교.

0

이 좋은 시작이다 : 예를 들어

public class MyComparator extends Comparator<Date> { 
    public int compare(Date o1, Date o2){ 
     return o1.getTime() - o2.getTime(); 
    } 
} 

:

TreeSet<Date> ts = new TreeSet<Date>(new MyComparator()); 
ts.add(new Date(98796541)); 
ts.add(new Date(59586541)); 
System.out.println("Earlier is " + ts.first()); 
1

세 가지 방법이 있습니다 당신이

public static int compareTo(Date a, Date b) { 
    if (a.equals(b)) return 0; 
    return (a.before(b) ? -1 : 1); 
} 
관련 문제