Java Utililty Methods TimeUnit Convert

List of utility methods to do TimeUnit Convert

Description

The list of methods to do TimeUnit Convert are organized into topic(s).

Method

DoubletoMillis(Double sourceValue, TimeUnit sourceUnit)
to Millis
if (sourceUnit == null || sourceValue == null) {
    return null;
switch (sourceUnit) {
case DAYS:
    return sourceValue * 86400000;
case MICROSECONDS:
    return sourceValue * 0.001;
...
longtoMillis(final long interval, final TimeUnit tu)
Convert time interval to milliseconds.
if (interval < 0L) {
    throw new IllegalArgumentException("SleepUtilities.toMillis " + "Negative interval");
long millis = 0L;
switch (tu) {
case SECONDS:
    millis = tu.toMillis(interval);
    break;
...
longtoMillis(int duration, TimeUnit unit)
Convert time duration to milliseconds.
switch (unit) {
case DAYS:
    return duration * 86400 * 1000;
case HOURS:
    return duration * 3600 * 1000;
case MINUTES:
    return duration * 60 * 1000;
case SECONDS:
...
longtoMillis(long duration, TimeUnit timeUnit)
to Millis
return TimeUnit.MILLISECONDS.convert(duration, timeUnit);
longtoMillis(long duration, TimeUnit unit)
-1 means infinite.
if (duration == 0 || unit == null) {
    return 0;
} else if (duration < 0) {
    return -1;
} else {
    return unit.toMillis(duration);
longtoMillis(long time, TimeUnit unit)
Convert the specified duration expressed in the specfied time unit into milliseconds.
long millis = TimeUnit.MILLISECONDS.equals(unit) ? time : unit.convert(time, TimeUnit.MILLISECONDS);
long remainder = 0L;
if (TimeUnit.NANOSECONDS.equals(unit)) {
    remainder = time % 1000000L;
    if (remainder >= 500000L)
        millis++;
} else if (TimeUnit.MICROSECONDS.equals(unit)) {
    remainder = time % 1000L;
...
longtoMillis(String timeUnitString, String timeValue)
Converts timeValue in timeUnitString to milliseconds
TimeUnit timeUnit = timeUnitFromString(timeUnitString);
return (timeUnit == null) ? Long.MIN_VALUE : timeUnit.toMillis(Long.parseLong(timeValue));
longtoNanos(long timeout, TimeUnit unit)
to Nanos
return timeout < 0 ? -1 : (timeout == 0 ? 0 : (((timeout = unit.toNanos(timeout)) < 0) ? 0 : timeout));
inttoSeconds(long duration, TimeUnit timeUnit)
to Seconds
int seconds = (int) timeUnit.toSeconds(duration);
long inverseDuration = timeUnit.convert(seconds, TimeUnit.SECONDS);
if (duration > inverseDuration) {
    seconds++;
return seconds;
longtoSeconds(long timeout, TimeUnit unit)
Converts the given timeout to seconds.
return roundUpIfNecessary(timeout, unit.toSeconds(timeout));