Java Second Format formatSeconds(long dSeconds, boolean exact)

Here you can find the source of formatSeconds(long dSeconds, boolean exact)

Description

format Seconds

License

Open Source License

Declaration

public static String formatSeconds(long dSeconds, boolean exact) 

Method Source Code

//package com.java2s;

public class Main {
    public static String formatSeconds(long dSeconds, boolean exact) {
        int iSeconds = (int) dSeconds;
        int seconds = iSeconds % 60;
        int minutes = iSeconds / 60 % 60;
        int hours = iSeconds / 3600 % 24;
        int days = iSeconds / 86400;
        String sSeconds = seconds + "s";
        if (days == 0 && hours == 0 && minutes == 0) {
            return sSeconds;
        }/*from   w  w  w  . j  ava  2  s .c  om*/
        String sMinutes = minutes + "min " + sSeconds;
        if (days == 0 && hours == 0) {
            return sMinutes;
        }
        String sHours = hours + "h " + (exact ? sMinutes : minutes + "min ");
        if (days == 0) {
            return sHours;
        }
        return days + "d " + (exact ? sHours : hours + "h ");
    }
}

Related

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