Here you can find the source of formatTimeMillis(long timeMillis)
Parameter | Description |
---|---|
timeMillis | duration to convert |
public static String formatTimeMillis(long timeMillis)
//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"; } }