Java Milli Second to Minute hoursMinutes(long p_milliseconds)

Here you can find the source of hoursMinutes(long p_milliseconds)

Description

Convert the given number of milliseconds into an array of longs, where each long represents the hours, and minutes respectively.

License

Apache License

Parameter

Parameter Description
p_milliseconds a long value representing the number of milliseconds to convert

Return

an array of longs, where long[0] = hours, and long[1] = minutes.

Declaration

public static long[] hoursMinutes(long p_milliseconds) 

Method Source Code

//package com.java2s;
/**/*from   ww w. ja  va 2s  . c  om*/
 *  Copyright 2009 Welocalize, Inc. 
 *  
 *  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 {
    private static final long MILLIS_PER_SECOND = 1000;
    private static final long SECONDS_PER_MINUTE = 60;
    private static final long MINUTES_PER_HOUR = 60;

    /**
     * Convert the given number of milliseconds into an array of longs,
     * where each long represents the hours, and minutes respectively.
     *
     * @param p_milliseconds a long value representing the number of milliseconds
     * to convert
     *
     * @return an array of longs, where long[0] = hours, and
     * long[1] = minutes.
     */
    public static long[] hoursMinutes(long p_milliseconds) {
        long[] hm = new long[2];
        long seconds = p_milliseconds / MILLIS_PER_SECOND;
        long minutes = seconds / SECONDS_PER_MINUTE;
        long hours = minutes / MINUTES_PER_HOUR;
        minutes -= (hours * MINUTES_PER_HOUR);

        hm[0] = hours;
        hm[1] = minutes;
        return hm;
    }
}

Related

  1. _toBeginOfMinute(long millis)
  2. asHoursMinutesSeconds(long milliseconds)
  3. daysHoursMinutes(long p_milliseconds)
  4. daysHoursMinutesToMillis(String expression)
  5. isLessThanMinute(final long timeInMillis)
  6. isSameMinuteOfMillis(final long ms1, final long ms2)
  7. millis2minutes(long millis)
  8. millisecondsToMinutes(long ms)