Java TimeUnit Usage calculateRuntime(long startTime, long endTime)

Here you can find the source of calculateRuntime(long startTime, long endTime)

Description

calculate Runtime

License

Apache License

Declaration

public static String calculateRuntime(long startTime, long endTime) 

Method Source Code

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

import java.util.concurrent.TimeUnit;

public class Main {
    public static String calculateRuntime(long startTime, long endTime) {
        long runTime = endTime - startTime;

        long minutes = TimeUnit.MILLISECONDS.toMinutes(runTime);
        runTime -= TimeUnit.MINUTES.toMillis(minutes);
        long seconds = TimeUnit.MILLISECONDS.toSeconds(runTime);
        runTime -= TimeUnit.SECONDS.toMillis(seconds);
        long millis = runTime;

        String runTimeStr = String.format("%d min, %d sec, %d ms", minutes,
                seconds, millis);/*  www .ja  va2s.c om*/

        return runTimeStr;
    }
}

Related

  1. age(long creationDate)
  2. areEqualTTL(final Integer ttlDuration1, final Integer ttlDuration2)
  3. calculateDaysBetween(final Calendar start, final Calendar end)
  4. calculateTime(final int seconds)
  5. calculateTime(float seconds)
  6. cancelledFuture()
  7. convertMilisecondsToDetail(long ms)