Java TimeUnit Convert millisToDuration(final int val, final TimeUnit unit)

Here you can find the source of millisToDuration(final int val, final TimeUnit unit)

Description

Converts the given duration value in milliseconds to the given unit.

License

Open Source License

Exception

Parameter Description
IllegalArgumentException if the unit is null. Thrown via APIgetter methods such as Transaction.getLockTimeout.

Declaration

public static long millisToDuration(final int val, final TimeUnit unit) 

Method Source Code

//package com.java2s;
/*-//  w ww.  j a  v a 2  s  . c o m
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002-2010 Oracle.  All rights reserved.
 *
 */

import java.util.concurrent.TimeUnit;

public class Main {
    /**
     * Converts the given duration value in milliseconds to the given unit.
     *
     * @throws IllegalArgumentException if the unit is null. Thrown via API
     * getter methods such as Transaction.getLockTimeout.
     */
    public static long millisToDuration(final int val, final TimeUnit unit) {
        if (unit == null) {
            throw new IllegalArgumentException("TimeUnit argument may not be null");
        }
        return unit.convert(val, TimeUnit.MILLISECONDS);
    }
}

Related

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