Java TimeUnit Usage printTimeString(long time)

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

Description

print Time String

License

Open Source License

Declaration

public static String printTimeString(long time) 

Method Source Code

//package com.java2s;

import java.util.concurrent.TimeUnit;

public class Main {
    public static String printTimeString(long time) {
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        long diffSec = timeUnit.toSeconds(time);
        long diffMin = timeUnit.toMinutes(time);
        StringBuilder sb = new StringBuilder();
        sb.append(time).append(" ms");
        if (diffMin >= 1) {
            sb.append("(").append(diffMin).append("m").append(" ")
                    .append(diffSec - TimeUnit.MINUTES.toSeconds(diffMin)).append("s").append(")");
        } else if (diffSec >= 1) {
            sb.append("(").append(diffSec).append("s").append(")");
        }// w w w . ja v a2 s .  co  m
        return sb.toString();
    }
}

Related

  1. parseTimeMillis(String timeWithOrWithoutUnit)
  2. parseUntilTime(byte[] untilTime)
  3. pause()
  4. prettyMillis(long mil)
  5. printTimeMap(Map timeMap)
  6. printTiming(long start, long end)
  7. randomNanos(Random rand, int decimalDigits)
  8. rangeOf(final Date date, final int beforeDates, final int afterDates)
  9. roundTimestampToNexDay(long timestamp)