Java Time Format formatTime(final long time)

Here you can find the source of formatTime(final long time)

Description

format Time

License

Open Source License

Parameter

Parameter Description
time time in milliseconds

Return

Time formatted as X hours Y minutes Z seconds

Declaration

public static String formatTime(final long time) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from www  .jav  a  2  s  . c  o  m*/
     * @param time
     *            time in milliseconds
     * @return Time formatted as X hours Y minutes Z seconds
     */
    public static String formatTime(final long time) {
        long seconds = time / 1000;
        final long hours = seconds / 3600;
        final long minutes = (seconds % 3600) / 60;
        seconds = seconds % 60;

        final StringBuilder sb = new StringBuilder();
        if (hours != 0) {
            sb.append(hours).append(" hours ");
        }
        if (minutes != 0) {
            sb.append(minutes).append(" minutes ");
        }
        if (seconds != 0) {
            sb.append(seconds).append(" seconds");
        }

        return sb.toString();
    }
}

Related

  1. formatTime(byte[] btValue, int iOffset, int iLength)
  2. formatTime(double time)
  3. formatTime(double totalTime)
  4. formatTime(final int timeSec)
  5. formatTime(final long time)
  6. formatTime(final long timeMS)
  7. formatTime(float seconds)
  8. formatTime(int minutes)
  9. formatTime(int minutes)