Java TimeUnit Convert toSeconds(long duration, TimeUnit timeUnit)

Here you can find the source of toSeconds(long duration, TimeUnit timeUnit)

Description

to Seconds

License

Apache License

Declaration

public static int toSeconds(long duration, TimeUnit timeUnit) 

Method Source Code


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

import java.util.concurrent.TimeUnit;

public class Main {
    public static int toSeconds(long duration, TimeUnit timeUnit) {
        int seconds = (int) timeUnit.toSeconds(duration);
        long inverseDuration = timeUnit.convert(seconds, TimeUnit.SECONDS);

        if (duration > inverseDuration) {
            //Round up.
            seconds++;//w  ww  .  j ava2  s.c  o m
        }
        return seconds;
    }
}

Related

  1. toMillis(long duration, TimeUnit timeUnit)
  2. toMillis(long duration, TimeUnit unit)
  3. toMillis(long time, TimeUnit unit)
  4. toMillis(String timeUnitString, String timeValue)
  5. toNanos(long timeout, TimeUnit unit)
  6. toSeconds(long timeout, TimeUnit unit)
  7. toSeconds(long value, TimeUnit unit)
  8. toSIAbbreviation(final TimeUnit timeUnit)
  9. toString(TimeUnit unit)