Java Second Convert toDaySecondDifference(long difference)

Here you can find the source of toDaySecondDifference(long difference)

Description

to Day Second Difference

License

Open Source License

Declaration

public static String toDaySecondDifference(long difference) 

Method Source Code

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

public class Main {
    public static String toDaySecondDifference(long difference) {
        difference *= difference > 0 ? .001 : -.001;
        if (difference == 0) {
            return "0 seconds";
        }//from  w w w  .  j  av  a  2  s .c  o m
        StringBuilder ret = new StringBuilder();

        difference = append(ret, difference, 60 * 60 * 24, "day");
        difference = append(ret, difference, 60 * 60, "hour");
        difference = append(ret, difference, 60, "minute");
        append(ret, difference, 1, "second");
        return ret.toString();
    }

    private static long append(StringBuilder sb, long val, long min, String desc) {
        long v = val / min;
        if (v > 0) {
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(v).append(" ").append(desc);
            if (v > 1) {
                sb.append("s");
            }
        }
        return val - v * min;
    }
}

Related

  1. secondsToTimeString(long seconds)
  2. secondsToYWDHMS(long seconds)
  3. SecondToMin(double asec)
  4. timeStringToSeconds(String str)
  5. toCentiSeconds(float t)
  6. toHhMmSs(long seconds)
  7. toNanoseconds(long sec, long nanos)
  8. toSeconds(double value)
  9. toSeconds(long date)