Java Millisecond Convert millisToTimeSpan(long millis)

Here you can find the source of millisToTimeSpan(long millis)

Description

millis To Time Span

License

Creative Commons License

Declaration

public static String millisToTimeSpan(long millis) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

public class Main {
    public static String millisToTimeSpan(long millis) {
        if (millis < 60 * 1000) {
            long unit = roundUp(millis / 1000);
            return unit + (unit == 1 ? " second" : " seconds");
        } else if (millis < 60 * 1000 * 60) {
            long unit = roundUp(millis / 60000);
            return unit + (unit == 1 ? " minute" : " minutes");
        } else if (millis < 60 * 1000 * 60 * 24) {
            long unit = roundUp(millis / (60000 * 60));
            return unit + (unit == 1 ? " hour" : " hours");
        } else {//  www.  j a v  a2  s.c  o m
            long unit = roundUp(millis / (60000 * 60 * 24));
            return unit + (unit == 1 ? " day" : " days");
        }
    }

    private static long roundUp(double d) {
        return Math.round(d * 10.0) / 10;
    }
}

Related

  1. millisToText(long millis)
  2. millisToTime(final long time)
  3. millisToTime(float millis)
  4. millisToTime(long ms)
  5. millisToTimeSpan(final long interv)
  6. MillisToTimeString(long millis)
  7. millisToWords(long millis)
  8. toMillis(int seconds)
  9. toMillis(int timeInSecs)