Java Second Format formatSeconds(int seconds)

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

Description

Formats the specified amount of seconds to a short format.

License

Apache License

Parameter

Parameter Description
seconds seconds to be formatted

Return

the formatted seconds in short format

Declaration

public static String formatSeconds(int seconds) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*  w  ww .ja  va 2  s.  c  om*/
     * Formats the specified amount of seconds to a short format.
     * @param seconds seconds to be formatted
     * @return the formatted seconds in short format
     */
    public static String formatSeconds(int seconds) {
        int hour = 0, min = 0;

        if (seconds >= 3600) {
            hour = seconds / 3600;
            seconds = seconds % 3600;
        }
        if (seconds >= 60) {
            min = seconds / 60;
            seconds = seconds % 60;
        }

        return hour > 0 ? hour + (min < 10 ? ":0" : ":") + min + (seconds < 10 ? ":0" : ":") + seconds
                : min + (seconds < 10 ? ":0" : ":") + seconds;
    }
}

Related

  1. formatSeconds(double seconds)
  2. formatSeconds(double seconds)
  3. formatSeconds(double seconds, int precision)
  4. formatSeconds(double value)
  5. formatSeconds(final int total)
  6. formatSeconds(int seconds)
  7. formatSeconds(long dSeconds, boolean exact)
  8. formatSeconds(long millis)
  9. formatSeconds(long s, boolean letters)