Here you can find the source of hoursAndMinsToMilliseconds(int sign, int hours, int minutes)
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.
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. |
Parameter | Description |
---|---|
IllegalArgumentException | The magnitude of one or both of the hours or minutes value is outside the acceptable range. |
public final static int hoursAndMinsToMilliseconds(int sign, int hours, int minutes) throws IllegalArgumentException
//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); } }