Java TimeUnit Usage secondsToETA(long secondsTotal)

Here you can find the source of secondsToETA(long secondsTotal)

Description

seconds To ETA

License

Open Source License

Declaration

public static String secondsToETA(long secondsTotal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    public static String secondsToETA(long secondsTotal) {
        long hours = TimeUnit.SECONDS.toHours(secondsTotal);
        long minutes = TimeUnit.SECONDS.toMinutes(secondsTotal)
                - TimeUnit.HOURS.toMinutes(TimeUnit.SECONDS.toHours(secondsTotal));
        long seconds = secondsTotal - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(secondsTotal));
        String str;//  w  ww  .j ava  2s. co  m
        if (hours > 0) {
            str = String.format("%02d:%02d:%02ds", hours, minutes, seconds);
        } else if (minutes > 0) {
            str = String.format("%02d:%02ds", minutes, seconds);
        } else {
            str = String.format("%02ds", seconds);
        }
        return str;
    }
}

Related

  1. run(Callable task, long timeout)
  2. second(long second)
  3. seconds(long timeInMillis)
  4. secondsFromNow(long seconds)
  5. secondsPassed(int startTime)
  6. secondsToHMS(long seconds)
  7. secondsToMillis(int seconds)
  8. secondsToYearsDaysHoursMinutesSeconds(double seconds)
  9. selectDurationUnitForDisplay(long durationInNanos)