Here you can find the source of getElapsedTime(Date start, Date end)
public static String getElapsedTime(Date start, Date end)
//package com.java2s; /*/*from ww w .j av a 2s . c om*/ * Copyright (c) 2012-2014, John Campbell and other contributors. All rights reserved. * * This file is part of Tectonicus. It is subject to the license terms in the LICENSE file found in * the top-level directory of this distribution. The full list of project contributors is contained * in the AUTHORS file found in the same location. * */ import java.util.Date; import java.util.concurrent.TimeUnit; public class Main { public static String getElapsedTime(Date start, Date end) { long duration = end.getTime() - start.getTime(); final long days = TimeUnit.MILLISECONDS.toDays(duration); duration -= TimeUnit.DAYS.toMillis(days); final long hours = TimeUnit.MILLISECONDS.toHours(duration); duration -= TimeUnit.HOURS.toMillis(hours); final long minutes = TimeUnit.MILLISECONDS.toMinutes(duration); duration -= TimeUnit.MINUTES.toMillis(minutes); final long seconds = TimeUnit.MILLISECONDS.toSeconds(duration); String result = ""; if (days > 0) { result += days + " days "; } if (hours > 0) { result += hours + " hours "; } if (minutes > 0) { result += minutes + " minutes "; } return result + seconds + " seconds"; } }