Java TimeUnit Usage getPrettyTime(long duration)

Here you can find the source of getPrettyTime(long duration)

Description

get Pretty Time

License

Open Source License

Declaration

static String getPrettyTime(long duration) 

Method Source Code


//package com.java2s;

import java.util.concurrent.TimeUnit;

public class Main {
    static String getPrettyTime(long duration) {
        if (duration <= 0)
            throw new IllegalArgumentException();

        return String.format("%02d:%02d:%02d.%03d", TimeUnit.MILLISECONDS.toHours(duration),
                TimeUnit.MILLISECONDS.toMinutes(duration)
                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)),
                TimeUnit.MILLISECONDS.toSeconds(duration)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)),
                duration - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(duration)));
    }/*  w  w  w .java2  s.c om*/
}

Related

  1. getMinutesBetweenDates(Date begin_date, Date end_date)
  2. getMinutesBetweenDates(Date firstDate, Date secondDate)
  3. getNormalizedIntervalStartTimestamp(long intervalLengthMillis, long currentTimestamp)
  4. getNowInSeconds()
  5. getOceanTime(final Date date)
  6. getQuantilesString(final Map quantilesValues)
  7. getRandomDate()
  8. getReadableElapsedIntervalInSeconds(final long elapsedTimInMillis)
  9. getRemainingTimeString(int completedCount, int totalCount, long elapsed)