怎么判断两个datefield的大小。
也就是哪个先哪个后?

解决方案 »

  1.   

    datefiled是jvaa.sql.Date类型吧,或者就算是java.util.Date类型也好,反正java.sql.Date也是从java.util.Date继承的。java.util.Date有一个compareTo方法,参数是另一个java.util.Date,
    如果两个日期/时间相等,返回0,如果当前日期更先,反回值小于0,剩下那种情况返回值大于0
      

  2.   

    请查阅API中关于java.util.GregorianCalendar相关信息
      

  3.   


    谢谢 jamesfancy(▲) 边城狂人 的回答,不过j2se好像没有compareTo的方法。问题我已经解决.
    datefiled.getDate().getTime()   可以用这个解决
      

  4.   

    J2SE,从1.2开始就有compareTo方法了,怎么会没有呢?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