Java TimeUnit Convert toMillis(Double sourceValue, TimeUnit sourceUnit)

Here you can find the source of toMillis(Double sourceValue, TimeUnit sourceUnit)

Description

to Millis

License

Open Source License

Declaration

public static Double toMillis(Double sourceValue, TimeUnit sourceUnit) 

Method Source Code


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

import java.util.concurrent.TimeUnit;

public class Main {
    public static Double toMillis(Double sourceValue, TimeUnit sourceUnit) {
        if (sourceUnit == null || sourceValue == null) {
            return null;
        }/*  w w w . j av  a 2  s  .c om*/

        switch (sourceUnit) {
        case DAYS:
            return sourceValue * 86400000;
        case MICROSECONDS:
            return sourceValue * 0.001;
        case HOURS:
            return sourceValue * 3600000;
        case MILLISECONDS:
            return sourceValue;
        case MINUTES:
            return sourceValue * 60000;
        case NANOSECONDS:
            return sourceValue * 1.0e-6;
        case SECONDS:
            return sourceValue * 1000;
        default:
            return sourceValue;
        }
    }
}

Related

  1. millisToDuration(final int val, final TimeUnit unit)
  2. stringToTimeUnit(String str)
  3. substract(Date date, long durationToSubstract, TimeUnit unit)
  4. timeToNanoSeconds(TimeUnit unit, long time)
  5. toIntervalFromNow(long timeback, TimeUnit unit)
  6. toMillis(final long interval, final TimeUnit tu)
  7. toMillis(int duration, TimeUnit unit)
  8. toMillis(long duration, TimeUnit timeUnit)
  9. toMillis(long duration, TimeUnit unit)