Here you can find the source of humanReadableTime(final long duration)
public static String humanReadableTime(final long duration)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 Cloud Bees, Inc./*from w w w .j a v a2s .c o m*/ * All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Cloud Bees, Inc. - initial API and implementation *******************************************************************************/ public class Main { public static String humanReadableTime(final long duration) { String unit = ""; long mins = duration / (60L * 1000); long hr = mins / 60; long yrs = hr / 24 / 365; if (mins <= 0) { long secs = duration / 1000; unit = secs + " sec"; if (secs > 1) { unit = unit + "s"; } } else if (mins < 60) { unit = mins + " min"; if (mins > 1) { unit = unit + "s"; } } else if (mins < 60 * 24) { //long newmins = mins - (hr * 60); unit = hr + " hr" + (hr > 1 ? "s" : "");/* + " " + newmins + " min" + (newmins > 1 ? "s" : "");*/ } else if (yrs < 1) { long days = hr / 24L; unit = days + " day" + (days > 1 ? "s" : "")/* + ", " + hr + " hr" + (hr > 1 ? "s" : "")*/; } else { unit = yrs + " year" + (yrs > 1 ? "s" : ""); } return unit; } }