Here you can find the source of calcTimeBetween(Date start, Date end)
public static String calcTimeBetween(Date start, Date end)
//package com.java2s; //License from project: Open Source License import java.util.Date; public class Main { public static String calcTimeBetween(Date start, Date end) { int SECOND = 1000; int MINUTE = SECOND * 60; int HOUR = MINUTE * 60; int DAY = HOUR * 24; int milliSeconds = Math.round(end.getTime() - start.getTime()); if (milliSeconds > DAY) { return String.format("%d days", Math.round(milliSeconds / DAY)); }/*from w w w.ja v a2s . c o m*/ if (milliSeconds < DAY && milliSeconds > HOUR) { return String.format("%d hours", Math.round(milliSeconds / HOUR)); } if (milliSeconds < HOUR) { return String.format("%d minutes", Math.round(milliSeconds / MINUTE)); } //Throw an exception instead? return null; } }