Java Time Format formatTimeInMilisec(long time)

Here you can find the source of formatTimeInMilisec(long time)

Description

format Time In Milisec

License

Open Source License

Declaration

public static String formatTimeInMilisec(long time) 

Method Source Code

//package com.java2s;

public class Main {
    public static String formatTimeInMilisec(long time) {
        if (time / 1000 < 1) {
            return "0 seconds";
        }//from w  w w. j av  a 2 s. c  o  m
        long inMinutes = time / 60000;
        long hours = inMinutes / 60;
        String formatedTime = "";
        if (hours > 0) {
            String unit = hours > 1 ? "hours" : "hour";
            formatedTime = hours + " " + unit;
        }
        long minutes = inMinutes - hours * 60;
        if (minutes > 0) {
            String unit = minutes > 1 ? "minutes" : "minute";
            formatedTime = formatedTime + " " + minutes + " " + unit;
        }
        long seconds = (time / 1000) - minutes * 60 - hours * 60 * 60;
        if (seconds > 0) {
            String unit = minutes > 1 ? "seconds" : "second";
            formatedTime = formatedTime + " " + seconds + " " + unit;
        }
        return formatedTime;
    }
}

Related

  1. formatTimeDifference(long time1, long time2)
  2. formatTimeDigital(int time)
  3. formatTimeDuringHour(long mss)
  4. formatTimeElapsed(long p_millis)
  5. formatTimeInfo(long time)
  6. formatTimeInNanos(long time)
  7. formatTimeInterval(final long time)
  8. formatTimeInterval(long in)
  9. formatTimeLength(long ms)