Java Time Elapsed elapsedTime(long timeInMs)

Here you can find the source of elapsedTime(long timeInMs)

Description

elapsed Time

License

Open Source License

Declaration

public static String elapsedTime(long timeInMs) 

Method Source Code

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

public class Main {
    public static String elapsedTime(long timeInMs) {
        String r;//from   w ww. j ava 2  s.  co  m
        long time = (int) (timeInMs / 1000);
        long secs = time % 60 > 0 ? time % 60 : 0;
        time = time / 60;
        long mins = time % 60 > 0 ? time % 60 : 0;
        time = time / 60;
        long hours = time % 24 > 0 ? time % 24 : 0;
        long days = time / 24;

        r = String.valueOf(secs);
        String s = secs > 1 ? " seconds " : " second ";
        r = r + s;
        if (mins > 0) {
            String m = (mins > 1) ? " minutes " : " minute ";
            r = mins + m + r;
        }
        if (hours > 0) {
            String h = (hours > 1) ? " hours " : " hour ";
            r = hours + h + r;
        }
        if (days > 0) {
            String d = (days > 1) ? " days " : " day ";
            r = days + d + r;
        }
        return r;
    }
}

Related

  1. elapsedNanos(long startNanoTime)
  2. elapsedTime(long endTime, long beginTime)
  3. elapsedTime(long milli)
  4. elapsedTime(long ms)
  5. elapsedTime(long startTime, long endTime, double units)
  6. elapsedTimeMs(long start)
  7. elapsedTimeStamp(long time)
  8. elapsedTimeStampSection(long n, String label, StringBuffer sb)
  9. elapsedTimeString(long time)