判断某一日期在另外一个日期之前

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1.调用方式

oneDate.compareTo(anotherDate);

2.函数源码

    /**
     * Compares two Dates for ordering.
     *
     * @param   anotherDate   the Date to be compared.
     * @return  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.
     * @since   1.2
     * @exception NullPointerException if anotherDate is null.
     */
    public int compareTo(Date anotherDate) {
        long thisTime = getMillisOf(this);
        long anotherTime = getMillisOf(anotherDate);
        return (thisTime

我们看到,判断的方式非常简单,就是根据时间的Long值进行判断的,如果Long值大就返回1,相等返回0,小的话返回-1。

转载于:https://my.oschina.net/hengbao666/blog/3011318

你可能感兴趣的:(判断某一日期在另外一个日期之前)