Here you can find the source of formatTimeSec(long time)
public static String formatTimeSec(long time)
//package com.java2s; /*//from ww w . j a v a2s. c om * Portions of this file Copyright 1999-2005 University of Chicago * Portions of this file Copyright 1999-2005 The University of Southern California. * * This file or a portion of this file is licensed under the * terms of the Globus Toolkit Public License, found at * http://www.globus.org/toolkit/download/license.html. * If you redistribute this file, with or without * modifications, you must include this notice in the file. */ public class Main { /** * Generates string representation of given time specified * as long. The format is: [days][,][h][,][min][,][sec] * */ public static String formatTimeSec(long time) { StringBuffer str = new StringBuffer(); if (time < 60) { str.append(time + " sec"); return str.toString(); } int days = (int) time / 86400; if (days != 0) { str.append(days + " days"); time -= days * 86400; } int hours = (int) time / 3600; if (hours != 0) { if (str.length() != 0) str.append(", "); str.append(hours + " h"); time -= hours * 3600; } int mins = (int) time / 60; if (mins != 0) { if (str.length() != 0) str.append(", "); str.append(mins + " min"); time -= mins * 60; } int sec = (int) time; if (sec != 0) { if (str.length() != 0) str.append(", "); str.append(sec + " sec"); } return str.toString(); } }