Java Time Format formatElapsedTime(int seconds)

Here you can find the source of formatElapsedTime(int seconds)

Description

format Elapsed Time

License

Open Source License

Parameter

Parameter Description
seconds an Int indicating the number of seconds that is to be formatted

Return

a String containing the formatted string value.

Declaration

public static String formatElapsedTime(int seconds) 

Method Source Code

//package com.java2s;
/*/* ww w. j av a  2  s .c o  m*/
 * THIS SOURCE FILE IS PART OF JBASIC, AN OPEN SOURCE PUBLICLY AVAILABLE
 * JAVA SOFTWARE PACKAGE HOSTED BY SOURCEFORGE.NET
 *
 * THIS SOFTWARE IS PROVIDED VIA THE GNU PUBLIC LICENSE AND IS FREELY
 * AVAILABLE FOR ANY PURPOSE COMMERCIAL OR OTHERWISE AS LONG AS THE AUTHORSHIP
 * AND COPYRIGHT INFORMATION IS RETAINED INTACT AND APPROPRIATELY VISIBLE
 * TO THE END USER.
 * 
 * SEE THE PROJECT FILE AT HTTP://WWW.SOURCEFORGE.NET/PROJECTS/JBASIC FOR
 * MORE INFORMATION.
 * 
 * COPYRIGHT 2003-2011 BY TOM COLE, TOMCOLE@USERS.SF.NET
 *
 * Created on Jun 23, 2007 by tom
 *
 */

public class Main {
    /**
     * @param seconds an Int indicating the number of seconds that is to
     * be formatted
     * @return a String containing the formatted string value.
     */
    public static String formatElapsedTime(int seconds) {

        String sPlural = (seconds == 1 ? "" : "s");

        if (seconds < 60)
            return Integer.toString(seconds) + " second" + sPlural;

        int s = (seconds % 60);
        sPlural = (seconds == 1 ? "" : "s");
        int m = seconds / 60;
        String mPlural = (m == 1 ? "" : "s");

        return Integer.toString(m) + " minute" + mPlural
                + (s > 0 ? (", " + Integer.toString(s) + " second" + sPlural) : "");

    }
}

Related

  1. formatDateTime(String DateTimeStr)
  2. formatDateTime(String s)
  3. formatDateTime(String value)
  4. formatDateTimeString(final String dateTimeString, final boolean wrapForCodeUsage)
  5. formatDelay(long startTime, long endTime)
  6. formatElapsedTime(long elapsedTime)
  7. formatElapsedTime(long time)
  8. formatEndRowKeyString(String id, String timestampEnd)
  9. formatExecutionTime(long executionTime)