Java Millisecond Format formatTimeMillis(long timeMillis)

Here you can find the source of formatTimeMillis(long timeMillis)

Description

Converts the passed duration in millisecands to a hour, min, sec, millisec string.

License

Apache License

Parameter

Parameter Description
timeMillis duration to convert

Return

formatted string

Declaration

public static String formatTimeMillis(long timeMillis) 

Method Source Code

//package com.java2s;
/**//w  w w. j a v  a  2  s.com
 * Copyright 2014 SAP AG
 *
 * 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 int kilo = 1000;
    private static final int SEC_IN_MIN = 60;
    private static final int MIN_IN_H = 60;

    /**
     * Converts the passed duration in millisecands to a hour, min, sec,
     * millisec string.
     * 
     * @param timeMillis
     *            duration to convert
     * @return formatted string
     */
    public static String formatTimeMillis(long timeMillis) {
        long milliSec = timeMillis % kilo;
        long secAll = timeMillis / kilo;

        long sec = secAll % SEC_IN_MIN;
        long minAll = secAll / SEC_IN_MIN;

        long min = minAll % MIN_IN_H;
        long h = minAll / MIN_IN_H;

        return h + " h - " + min + " min - " + sec + " s - " + milliSec
                + " ms";
    }
}

Related

  1. formatTime(long localCreationTimeMillis)
  2. formatTime(long millis)
  3. formatTime(long millis)
  4. formatTimeInMillis(long millis)
  5. formatTimeMillis(long millis)
  6. formatTimestamp(long millis)
  7. formatTimeWithMillis(double time)
  8. getFormatedDateTime(long millis)
  9. getFormattedAPILastAccessDate(long lastAccessTimeMillis)