Here you can find the source of hoursToUnit(double hours, TimeUnit destinationUnit)
public static double hoursToUnit(double hours, TimeUnit destinationUnit)
//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); } } }