Here you can find the source of getDifference(Calendar initDate, Calendar endDate, TimeUnit units)
public static long getDifference(Calendar initDate, Calendar endDate, TimeUnit units)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.concurrent.TimeUnit; public class Main { public static long getDifference(Calendar initDate, Calendar endDate, TimeUnit units) { return units.convert(endDate.getTimeInMillis() - initDate.getTimeInMillis(), TimeUnit.MILLISECONDS); }/*from ww w . j av a 2 s. co m*/ }