Java Date Compare compareYear(java.util.Date date1, java.util.Date date2)

Here you can find the source of compareYear(java.util.Date date1, java.util.Date date2)

Description

compare Year

License

Open Source License

Declaration

public static int compareYear(java.util.Date date1, java.util.Date date2) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

public class Main {

    public static int compareYear(java.util.Date date1, java.util.Date date2) {
        if (date1 == null || date2 == null)
            return 0;

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date1);/*w  w  w.j a va  2  s. c  om*/
        int year1 = calendar.get(Calendar.YEAR);

        calendar.setTime(date2);
        int year2 = calendar.get(Calendar.YEAR);

        return year1 - year2;
    }
}

Related

  1. compareTimesOfDay(Date time1, Date time2)
  2. compareTo(Date src, Date dest)
  3. compareToCal(Date sDate, Date eDate)
  4. compareToMonthByDate(Date startDate, Date endDate)
  5. compareTwoDate(Date beforeDate, Date afterDate)
  6. compareYMD(Date begindate, Date enddate)
  7. compDate(Date date1, Date date2)
  8. compDate4(Date date1, Date date2)
  9. getCompareDate(Date startDate, Date endDate)