Java Utililty Methods Time Elapsed

List of utility methods to do Time Elapsed

Description

The list of methods to do Time Elapsed are organized into topic(s).

Method

StringelapsedTime(long timeInMs)
elapsed Time
String r;
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;
...
longelapsedTimeMs(long start)
Get the elapsed time in millisecond between the specified start time and now.
return System.currentTimeMillis() - start;
StringelapsedTimeStamp(long time)
put your documentation comment here
StringBuffer sb = new StringBuffer();
elapsedTimeStampSection(time / 86400000L, "day", sb);
elapsedTimeStampSection((time % 86400000L) / 3600000L, "hour", sb);
elapsedTimeStampSection((time % 3600000L) / 1000L, "second", sb);
return sb.toString();
voidelapsedTimeStampSection(long n, String label, StringBuffer sb)
put your documentation comment here
if (n > 0) {
    if (sb.length() > 0)
        sb.append(", ");
    sb.append(n);
    sb.append(' ');
    sb.append(label);
    if (n > 1)
        sb.append('s');
...
StringelapsedTimeString(long time)
elapsed Time String
final long DAY = 86400000;
final long HOUR = 3600000;
final long MIN = 60000;
long remaintime = time;
long days = remaintime / DAY;
remaintime = remaintime - DAY * days;
long hours = remaintime / HOUR;
remaintime = remaintime - HOUR * hours;
...