Java TimeUnit Usage getReadableElapsedIntervalInSeconds(final long elapsedTimInMillis)

Here you can find the source of getReadableElapsedIntervalInSeconds(final long elapsedTimInMillis)

Description

get Readable Elapsed Interval In Seconds

License

Open Source License

Declaration

public static String getReadableElapsedIntervalInSeconds(final long elapsedTimInMillis) 

Method Source Code

//package com.java2s;

import java.util.concurrent.TimeUnit;

public class Main {
    public static String getReadableElapsedIntervalInSeconds(final long elapsedTimInMillis) {
        final long hours = TimeUnit.MILLISECONDS.toHours(elapsedTimInMillis);
        final long minutes = TimeUnit.MILLISECONDS.toMinutes(elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours));
        final long seconds = TimeUnit.MILLISECONDS
                .toSeconds(elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours) - TimeUnit.MINUTES.toMillis(minutes))
                + (hours * 60 * 60) + (minutes * 60);
        final long milliSeconds = TimeUnit.MILLISECONDS.toMillis(elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours)
                - TimeUnit.MINUTES.toMillis(minutes) - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(
                        elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours) - TimeUnit.MINUTES.toMillis(minutes))));
        return String.format("%02d.%03d", seconds, milliSeconds);
    }/*from  w w  w . jav  a2 s  .c  o  m*/
}

Related

  1. getNowInSeconds()
  2. getOceanTime(final Date date)
  3. getPrettyTime(long duration)
  4. getQuantilesString(final Map quantilesValues)
  5. getRandomDate()
  6. getRemainingTimeString(int completedCount, int totalCount, long elapsed)
  7. getSeconds(long time)
  8. getSecondsDateDiff(Date dateStart)
  9. getSecondsTimeStamp()