Java Date Compare compare2Date(Date date1, Date date2)

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

Description

date2 return 0 ,date1==date2 return 1, date1License Apache License

Parameter

Parameter Description
date1 a parameter
date2 a parameter

Declaration

public static int compare2Date(Date date1, Date date2) 

Method Source Code


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

import java.util.*;

public class Main {
    /******************************************************************************
     * <date , date1>date2 return 0 ,date1==date2 return 1, date1<date2
     * return 1; exception return -1;//ww w . j  a v  a  2 s  .c o  m
     * 
     * @param date1
     * @param date2
     * @return
     */
    public static int compare2Date(Date date1, Date date2) {
        try {
            if (date1.after(date2)) {
                return 0;
            } else if (date1.equals(date2)) {
                return 1;
            } else {
                return 2;
            }
        } catch (Exception e) {
            return -1;
        }
    }
}

Related

  1. compare(Date start, Date end)
  2. compare(Date start, String end)
  3. compare(Date startDate, Date endDate, Date targetDate)
  4. compare(final Date lhs, final Date rhs)
  5. compare(final Date one, final Date another)
  6. compare2Dates(Date d1, Date d2)
  7. compare2DateString(String DateStringType, String dateStr1, String dateStr2)
  8. compare_date2(String finalDate, String enddate)
  9. compareCalendars(Date fechaAComparar, Date fechaBase)