Java Date Compare compare(final Date one, final Date another)

Here you can find the source of compare(final Date one, final Date another)

Description

compare

License

Open Source License

Declaration

protected static Integer compare(final Date one, final Date another) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;
import java.util.Date;

public class Main {

    protected static Integer compare(final Date one, final Date another) {
        if (one == null || another == null) {
            return null;
        }// w ww  .j  a  v a2 s. c  o  m
        final Calendar cal1 = Calendar.getInstance();
        final Calendar cal2 = Calendar.getInstance();
        cal1.setTime(one);
        cal2.setTime(another);
        int age = Math.abs(cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR));
        return cal1.getTime().before(cal2.getTime()) ? age-- : age;
    }
}

Related

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