Java Long Number Readable Format humanReadableDateDiff(long start, long end)

Here you can find the source of humanReadableDateDiff(long start, long end)

Description

human Readable Date Diff

License

Apache License

Declaration

public static String humanReadableDateDiff(long start, long end) 

Method Source Code

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

public class Main {
    public static String humanReadableDateDiff(long start, long end) {
        long diff = end - start;
        StringBuilder sb = new StringBuilder();
        long days = diff / (24 * 60 * 60 * 1000);
        diff -= days * 24 * 60 * 60 * 1000;
        if (days >= 1) {
            sb.append(days);/*w w  w. j  a  va2 s  . c o m*/
            sb.append("d");
        }

        long hours = diff / (60 * 60 * 1000);
        diff -= hours * 60 * 60 * 1000;
        if (hours >= 1) {
            if (sb.length() > 1) {
                sb.append(' ');
            }
            sb.append(hours);
            sb.append("h");
        }

        if (sb.length() > 1) {
            sb.append(' ');
        }

        long minutes = diff / (60 * 1000);
        diff -= minutes * 60 * 1000;
        sb.append(minutes);
        sb.append("m ");

        sb.append(Math.round(Math.ceil(diff / 1000.0)));
        sb.append("s");
        return sb.toString();
    }
}

Related

  1. humanReadableByteCount(long bytes, boolean si)
  2. humanReadableByteCount(long bytes, boolean si)
  3. humanReadableByteCount(long bytes, boolean si)
  4. humanReadableBytes(long bytes)
  5. humanReadableBytes(long bytes)
  6. humanReadableDuration(long length)
  7. humanReadableDuration(long ms)
  8. humanReadableInt(long number)
  9. humanReadableNumber(long total)