Here you can find the source of formatElapsedTime(int seconds)
Parameter | Description |
---|---|
seconds | an Int indicating the number of seconds that is to be formatted |
public static String formatElapsedTime(int seconds)
//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) : ""); } }