Java TimeUnit Convert millisecondsTo(long milliseconds, final TimeUnit timeUnit)

Here you can find the source of millisecondsTo(long milliseconds, final TimeUnit timeUnit)

Description

milliseconds To

License

Apache License

Declaration

public static long millisecondsTo(long milliseconds, final TimeUnit timeUnit) 

Method Source Code

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

import java.util.concurrent.TimeUnit;

public class Main {
    public static long millisecondsTo(long milliseconds, final TimeUnit timeUnit) {
        switch (timeUnit) {
        case MILLISECONDS:
            return TimeUnit.MILLISECONDS.toMillis(milliseconds);
        case NANOSECONDS:
            return TimeUnit.MILLISECONDS.toNanos(milliseconds);
        case MICROSECONDS:
            return TimeUnit.MILLISECONDS.toMicros(milliseconds);
        case SECONDS:
            return TimeUnit.MILLISECONDS.toSeconds(milliseconds);
        case MINUTES:
            return TimeUnit.MILLISECONDS.toMinutes(milliseconds);
        case HOURS:
            return TimeUnit.MILLISECONDS.toHours(milliseconds);
        case DAYS:
            return TimeUnit.MILLISECONDS.toDays(milliseconds);
        default:/*from  ww w .ja v  a2s.  co m*/
            throw new IllegalArgumentException();
        }
    }
}

Related

  1. convertToSecond(int interval, TimeUnit unit)
  2. durationToMillis(final long val, final TimeUnit unit)
  3. getDateRelativeToNow(TimeUnit timeUnit, long amount)
  4. getRemainingTimeToday(final TimeUnit timeUnit)
  5. hoursToUnit(double hours, TimeUnit destinationUnit)
  6. millisToDuration(final int val, final TimeUnit unit)
  7. stringToTimeUnit(String str)
  8. substract(Date date, long durationToSubstract, TimeUnit unit)
  9. timeToNanoSeconds(TimeUnit unit, long time)