commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 15082] New: - elapsed time formatting utility method
Date Wed, 04 Dec 2002 19:44:55 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15082>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15082

elapsed time formatting utility method

           Summary: elapsed time formatting utility method
           Product: Commons
           Version: 1.1 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: dan@dantanner.com


I haven't seen any public utilities out there that can display an elapsed time
in a human readable form.  I figured if it doesn't already exist in the commons,
it would be useful for others.  I'm not sure what package it would go in
(StringUtil or NumberUtil maybe?).  Anyway, here's a little public static method
that I use to get a readable elapsed time display for a time in milliseconds. 
Not that this is rocket science, but I found the guts of the code on some public
forum.  


---------------------------
    /**
     * Formats an elapsed time in milliseconds to a more human-readable form.
     * Output is in the format hh:mm:ss
     * @param elapsedMillis time in milliseconds.
     * @return the amount of time in hh:mm:ss format.
     */
    public static String formatTime(long elapsedMillis) {
        // first turn the amount in millis to be seconds...it's easier to format
the hhmmss that way.
        long elapsedSeconds = elapsedMillis / 1000;
        long formattedHours = elapsedSeconds / 3600;
        long formattedMinutes = (elapsedSeconds % 3600) / 60;
        long formattedSeconds = elapsedSeconds % 60;
        // if you also want formatted milliseconds, here's how...
        // long formattedMillis = elapsedMillis % 1000;
        return ((formattedHours < 10 ? "0" : "") + formattedHours + ":" +
                (formattedMinutes < 10 ? "0" : "") + formattedMinutes + ":" +
                (formattedSeconds < 10 ? "0" : "") + formattedSeconds);
    }
---------------------------------

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message