Here you can find the source of getDateDiff(Date date1, Date date2, TimeUnit timeUnit)
Parameter | Description |
---|---|
date1 | the oldest date |
date2 | the newest date |
timeUnit | the unit in which you want the diff |
public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit)
//package com.java2s; //License from project: Open Source License import java.util.Date; import java.util.concurrent.TimeUnit; public class Main { /**/*w ww . ja v a 2 s. c om*/ * Get a diff between two dates * @param date1 the oldest date * @param date2 the newest date * @param timeUnit the unit in which you want the diff * @return the diff value, in the provided unit */ public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) { long diffInMillies = date2.getTime() - date1.getTime(); return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS); } }