Code example for TimeUnit

Methods: convert

0
     * Note that the overhead of measurement can be more than a microsecond, so 
     * it is generally not useful to specify {@link TimeUnit#NANOSECONDS} 
     * precision here. 
     */ 
    public long elapsedTime(final TimeUnit desiredUnit) {
        return desiredUnit.convert(elapsedNanos(), NANOSECONDS);
    } 
 
    /** 
     * Returns the current elapsed time shown on this stopwatch, expressed in 
     * milliseconds, with any fraction rounded down. This is identical to 
     * {@code elapsedTime(TimeUnit.MILLISECONDS)}. 
     */ 
    public long elapsedMillis() { 
        return elapsedTime(MILLISECONDS);
    } 
 
    /** 
     * Returns a string representation of the current elapsed time. 
     */ 
    @Override