Java TimeUnit Convert convertToMilliseconds(TimeUnit timeUnit, long seed)

Here you can find the source of convertToMilliseconds(TimeUnit timeUnit, long seed)

Description

convert To Milliseconds

License

Open Source License

Declaration

public static long convertToMilliseconds(TimeUnit timeUnit, long seed) 

Method Source Code

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

import java.util.concurrent.TimeUnit;

public class Main {
    public static long convertToMilliseconds(TimeUnit timeUnit, long seed) {
        switch (timeUnit) {
        case MILLISECONDS:
            return seed;
        case SECONDS:
            return fromSeconds(seed);
        case MINUTES:
            return fromMinutes(seed);
        case HOURS:
            return fromHours(seed);
        case DAYS:
            return fromDays(seed);
        default:// ww  w  .  j a va2  s. c  om
            throw new IllegalArgumentException("Unsupported time unit. The smallest time unit supported is "
                    + TimeUnit.MILLISECONDS + " but got " + timeUnit);
        }
    }

    private static long fromSeconds(long seed) {
        return seed * 1000;
    }

    private static long fromMinutes(long seed) {
        return 60 * fromSeconds(seed);
    }

    private static long fromHours(long seed) {
        return 60 * fromMinutes(seed);
    }

    private static long fromDays(long seed) {
        return 24 * fromHours(seed);
    }
}

Related

  1. convert(TimeUnit unitTo, TimeUnit unitFrom, long cnt)
  2. convertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod, TimeUnit reportingTimeUnit)
  3. convertTo(long a, TimeUnit from, TimeUnit to)
  4. convertToDouble(long fromTime, TimeUnit fromTimeUnit, TimeUnit toTimeUnit)
  5. convertToMillis(long waitTime, TimeUnit timeUnit)
  6. convertToSecond(int interval, TimeUnit unit)
  7. durationToMillis(final long val, final TimeUnit unit)
  8. getDateRelativeToNow(TimeUnit timeUnit, long amount)
  9. getRemainingTimeToday(final TimeUnit timeUnit)