Java TimeUnit Convert hoursToUnit(double hours, TimeUnit destinationUnit)

Here you can find the source of hoursToUnit(double hours, TimeUnit destinationUnit)

Description

hours To Unit

License

Apache License

Declaration

public static double hoursToUnit(double hours, TimeUnit destinationUnit) 

Method Source Code

//package com.java2s;
/**/*from  w  w w .  j a v  a2s.  c  o  m*/
 * Copyright 2017 Pivotal Software, Inc.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.concurrent.TimeUnit;

public class Main {
    private static final long C0 = 1L;
    private static final long C1 = C0 * 1000L;
    private static final long C2 = C1 * 1000L;
    private static final long C3 = C2 * 1000L;
    private static final long C4 = C3 * 60L;
    private static final long C5 = C4 * 60L;
    private static final long C6 = C5 * 24L;

    public static double hoursToUnit(double hours, TimeUnit destinationUnit) {
        switch (destinationUnit) {
        case NANOSECONDS:
            return hours * (C5 / C0);
        case MICROSECONDS:
            return hours * (C5 / C1);
        case MILLISECONDS:
            return hours * (C5 / C2);
        case SECONDS:
            return hours * (C5 / C3);
        case MINUTES:
            return hours * (C5 / C4);
        case HOURS:
        default:
            return hours;
        case DAYS:
            return hours / (C6 / C5);
        }
    }
}

Related

  1. convertToMilliseconds(TimeUnit timeUnit, long seed)
  2. convertToSecond(int interval, TimeUnit unit)
  3. durationToMillis(final long val, final TimeUnit unit)
  4. getDateRelativeToNow(TimeUnit timeUnit, long amount)
  5. getRemainingTimeToday(final TimeUnit timeUnit)
  6. millisecondsTo(long milliseconds, final TimeUnit timeUnit)
  7. millisToDuration(final int val, final TimeUnit unit)
  8. stringToTimeUnit(String str)
  9. substract(Date date, long durationToSubstract, TimeUnit unit)