Java TimeUnit Convert convertTo(long a, TimeUnit from, TimeUnit to)

Here you can find the source of convertTo(long a, TimeUnit from, TimeUnit to)

Description

convert To

License

Open Source License

Declaration

public static long convertTo(long a, TimeUnit from, TimeUnit to) 

Method Source Code


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

import java.util.concurrent.TimeUnit;

public class Main {
    public static long convertTo(long a, TimeUnit from, TimeUnit to) {
        switch (to) {
        case NANOSECONDS:
            return from.toNanos(a);
        case MICROSECONDS:
            return from.toMicros(a);
        case MILLISECONDS:
            return from.toMillis(a);
        case SECONDS:
            return from.toSeconds(a);
        case MINUTES:
            return from.toMinutes(a);
        case HOURS:
            return from.toHours(a);
        case DAYS:
            return from.toDays(a);
        default:/*  w ww  . j  ava  2  s  .c o  m*/
            throw new IllegalArgumentException("TimeUnit \"" + to.toString() + "\" is not supported!");
        }
    }
}

Related

  1. convert(double t, TimeUnit sourceUnit, TimeUnit destinationUnit)
  2. convert(long time, TimeUnit src, TimeUnit dst)
  3. convert(long time, TimeUnit unitIn, TimeUnit unitOut)
  4. convert(TimeUnit unitTo, TimeUnit unitFrom, long cnt)
  5. convertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod, TimeUnit reportingTimeUnit)
  6. convertToDouble(long fromTime, TimeUnit fromTimeUnit, TimeUnit toTimeUnit)
  7. convertToMillis(long waitTime, TimeUnit timeUnit)
  8. convertToMilliseconds(TimeUnit timeUnit, long seed)
  9. convertToSecond(int interval, TimeUnit unit)