Java Day Between yearTimeDiff(Date d1, Date d2)

Here you can find the source of yearTimeDiff(Date d1, Date d2)

Description

year Time Diff

License

Apache License

Declaration

public static int yearTimeDiff(Date d1, Date d2) 

Method Source Code

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

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

public class Main {

    public static int yearTimeDiff(Date d1, Date d2) {
        assertDateParamsRequired(d1, d2);
        Calendar c1 = Calendar.getInstance();
        c1.setTime(d1);//  w ww .  j  av a 2  s  .  c  o m
        Calendar c2 = Calendar.getInstance();
        c2.setTime(d2);
        return c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR);
    }

    private static void assertDateParamsRequired(Date... dates) {
        for (Date date : dates) {
            if (date == null) {
                throw new IllegalArgumentException("The Date type parameters are required.");
            }
        }
    }
}

Related

  1. substractDate(final Date date, final Integer different)
  2. timeDifferenceInSeconds(Date startDate, Date endDate)
  3. timeDifferenceWithCurrentTime(Date startTime)
  4. truncateDifferMonths(Date date)
  5. yearDifference(Date date1, Date date2)