Java Date Compare compareDates(Date date1, Date date2)

Here you can find the source of compareDates(Date date1, Date date2)

Description

Compares the two dates.

License

LGPL

Parameter

Parameter Description
date1 the first date to compare
date2 the second date to compare with

Return

Returns 0 if the two dates are equals, a value < 0 if the first date is before the second one and > 0 if the first date is after the second one

Declaration

public static int compareDates(Date date1, Date date2) 

Method Source Code


//package com.java2s;
/*/*  w w  w .j  a v a  2  s.  c om*/
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

import java.util.*;

public class Main {
    /**
     * Compares the two dates. The comparison is based only on the day, month
     * and year values. Returns 0 if the two dates are equals, a value < 0 if
     * the first date is before the second one and > 0 if the first date is after
     * the second one.
     * @param date1 the first date to compare
     * @param date2 the second date to compare with
     * @return Returns 0 if the two dates are equals, a value < 0 if
     * the first date is before the second one and > 0 if the first date is after
     * the second one
     */
    public static int compareDates(Date date1, Date date2) {
        return date1.compareTo(date2);
    }

    /**
     * Compares the two dates. The comparison is based only on the day, month
     * and year values. Returns 0 if the two dates are equals, a value < 0 if
     * the first date is before the second one and > 0 if the first date is after
     * the second one.
     * @param date1 the first date to compare
     * @param date2 the second date to compare with
     * @return Returns 0 if the two dates are equals, a value < 0 if
     * the first date is before the second one and > 0 if the first date is after
     * the second one
     */
    public static int compareDates(long date1, long date2) {
        return (date1 < date2 ? -1 : (date1 == date2 ? 0 : 1));
    }
}

Related

  1. compareDate(String strDate1, String strDate2, String format)
  2. compareDate2(String begingDate, String endDate, String format)
  3. compareDateFormat(String strDate1, String strDate2, String format)
  4. compareDateForSecond(Date src, Date target, int second)
  5. compareDates(Date date1, Date date2)
  6. compareDates(final Date dateA, final Date dateB)
  7. compareDates(final String format, final Date date1, final Date date2)
  8. compareDateSequence(String startDate, String endDate)
  9. compareDatesOnly(long date1, long date2)