Java Second Format formatSeconds(long s, boolean letters)

Here you can find the source of formatSeconds(long s, boolean letters)

Description

format Seconds

License

Open Source License

Declaration

public static String formatSeconds(long s, boolean letters) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatSeconds(long s, boolean letters) {
        String string = "";

        if (s < 1)
            return "00:00";

        long remainder;
        long days = (int) s / 86400;
        long hours = (int) (s % 86400) / 3600;
        remainder = s - days * 86400 - hours * 3600;
        long mins = (int) remainder / 60;
        long secs = remainder % 60;

        if (days > 0) {
            string += days;//from w  w w . j a  v  a  2  s.co  m
            if (letters)
                string += "d";
        }
        if (hours > 0) {
            string += hours;
            if (letters)
                string += "h ";
        }
        if (mins < 10)
            string += "0" + mins + ":";
        else
            string += mins + ":";

        if (secs < 10)
            string += "0" + secs;
        else
            string += secs;

        return string;
    }
}

Related

  1. formatSeconds(final int total)
  2. formatSeconds(int seconds)
  3. formatSeconds(int seconds)
  4. formatSeconds(long dSeconds, boolean exact)
  5. formatSeconds(long millis)
  6. formatSeconds(long seconds)
  7. formatSeconds(long seconds)
  8. formatSeconds(long secsIn)
  9. formatSeconds(long time)