Here you can find the source of differenceInYears(final Calendar a, final Calendar b)
Parameter | Description |
---|---|
a | first element of substraction of dates. |
b | second element of substraction of dates. |
public static double differenceInYears(final Calendar a, final Calendar b)
//package com.java2s; /*/*from ww w. j av a2 s. co m*/ * Copyright 2011 - 2012 * All rights reserved. License and terms according to LICENSE.txt file. * The LICENSE.txt file and this header must be included or referenced * in each piece of code derived from this project. */ import java.util.*; public class Main { private static final long MILLISECONDS_PER_YEAR = 365 * 24 * 60 * 60 * 1000; /** * Calculates difference in years between to dates. * @param a first element of substraction of dates. * @param b second element of substraction of dates. * @return a-b in fractions of year. */ public static double differenceInYears(final Calendar a, final Calendar b) { final long millisDif = a.getTimeInMillis() - b.getTimeInMillis(); return millisDif / MILLISECONDS_PER_YEAR; } }