Java Hour hoursAndMinsToMilliseconds(int sign, int hours, int minutes)

Here you can find the source of hoursAndMinsToMilliseconds(int sign, int hours, int minutes)

Description

Converts a number of hours, minutes and seconds and a corresponding sign value to an equivalent offset value from UTC (Universal Coordinated Time), measured in milliseconds.

License

Apache License

Parameter

Parameter Description
sign Indicates a positive or negative offset from UTC.
hours Hours part of the magnitude of the offset from UTC.
minutes Minutes part of the magnitude of the offset from UTC.

Exception

Parameter Description
IllegalArgumentException The magnitude of one or both of the hours or minutes value is outside the acceptable range.

Return

Offset from UTC represented in milliseconds.

Declaration

public final static int hoursAndMinsToMilliseconds(int sign, int hours, int minutes)
        throws IllegalArgumentException 

Method Source Code

//package com.java2s;
/*//from  w w  w .j av  a  2 s  .c  o  m
 * Copyright 2016 Richard Cartwright
 *
 * 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
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

public class Main {
    /**
     * <p>Converts a number of hours, minutes and seconds and a corresponding sign value to an
     * equivalent offset value from UTC (Universal Coordinated Time), measured in milliseconds.
     * Timezone offsets available by calling methods of the {@link java.util.Calendar} class are
     * measured in milliseconds.</p>
     * 
     * <p>Any sign value specified with the hours or minutes values are ignored and their magnitudes
     * taken. Any positive value for the sign value, or zero, is taken to mean a positive offset
     * from UTC, otherwise the value is considered a negative value offset from UTC. The maximum permitted
     * offset from UTC is plus or minus 30 hours.</p> 
     *
     * @param sign Indicates a positive or negative offset from UTC.
     * @param hours Hours part of the magnitude of the offset from UTC.
     * @param minutes Minutes part of the magnitude of the offset from UTC.
     * @return Offset from UTC represented in milliseconds.
     * 
     * @throws IllegalArgumentException The magnitude of one or both of the hours or minutes value is outside 
     * the acceptable range.
     * 
     * @see java.util.Calendar#ZONE_OFFSET
     * @see java.util.Calendar#DST_OFFSET
     */
    public final static int hoursAndMinsToMilliseconds(int sign, int hours, int minutes)
            throws IllegalArgumentException {

        sign = (sign >= 0) ? 1 : -1;
        hours = (hours >= 0) ? hours : -hours;
        minutes = (minutes >= 0) ? minutes : -minutes;

        if ((hours > 30) || (minutes > 1800))
            throw new IllegalArgumentException(
                    "The magnitude of one or both of the hours or minutes value is outside the acceptable range.");
        return sign * (hours * 3600000 + minutes * 60000);
    }
}

Related

  1. hourAgo()
  2. hourCompletion(boolean hourPresent, int hour, boolean minutePresent, int minute, boolean secondPresent, int second, boolean milliPresent, int milli, String choice)
  3. HourNow()
  4. Hours()
  5. hours(int hours)
  6. isHour(int hour)
  7. nextHour(Date date)
  8. nextHour(int hour)
  9. resetHourMillisToZero(long millis)