Java Date Compare compare(final Date lhs, final Date rhs)

Here you can find the source of compare(final Date lhs, final Date rhs)

Description

Null-safe implementation to compare two dates against each other.

License

Apache License

Parameter

Parameter Description
lhs left-hand side date
rhs right-hand side date

Return

-1 if the left hand is earlier, 1 if it is later, and 0 if it is the same as the right side

Declaration

public static int compare(final Date lhs, final Date rhs) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**/*w  w w . jav  a 2  s  .c  om*/
     * Null-safe implementation to compare two dates against each other.
     *
     * @param lhs left-hand side date
     * @param rhs right-hand side date
     * @return -1 if the left hand is earlier, 1 if it is later, and 0 if it is the same as the right side
     */
    public static int compare(final Date lhs, final Date rhs) {
        if (lhs == null)
            return (rhs == null ? 0 : -1);
        if (lhs == rhs)
            return 0;
        if (rhs == null)
            return 1;

        return lhs.compareTo(rhs);
    }
}

Related

  1. compare(Date date1, Date date2, String format)
  2. Compare(Date dtA, Date dtB, boolean bUnkIsPast)
  3. compare(Date start, Date end)
  4. compare(Date start, String end)
  5. compare(Date startDate, Date endDate, Date targetDate)
  6. compare(final Date one, final Date another)
  7. compare2Date(Date date1, Date date2)
  8. compare2Dates(Date d1, Date d2)
  9. compare2DateString(String DateStringType, String dateStr1, String dateStr2)