Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.concurrent.*;

public class Main {
    public static String printTime(long time, TimeUnit unit) {
        long ns = TimeUnit.NANOSECONDS.convert(time, unit);
        long us = TimeUnit.MICROSECONDS.convert(time, unit);
        long ms = TimeUnit.MILLISECONDS.convert(time, unit);
        long secs = TimeUnit.SECONDS.convert(time, unit);

        if (secs > 0)
            return secs + "s";
        if (ms > 0)
            return ms + "ms";
        if (us > 0)
            return us + " us";
        return ns + "ns";
    }
}