Java Formatter Usage millisToHumanTime(long milliseconds)

Here you can find the source of millisToHumanTime(long milliseconds)

Description

Convert milliseconds to human time -the exact format is unspecified

License

Apache License

Parameter

Parameter Description
milliseconds a time in milliseconds

Return

a time that is converted to human intervals

Declaration

public static String millisToHumanTime(long milliseconds) 

Method Source Code

//package com.java2s;
/*/*from ww w  .  ja va2  s .  co m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */

import java.util.Formatter;

import java.util.Locale;

public class Main {
    /**
     * Convert milliseconds to human time -the exact format is unspecified
     * @param milliseconds a time in milliseconds
     * @return a time that is converted to human intervals
     */
    public static String millisToHumanTime(long milliseconds) {
        StringBuilder sb = new StringBuilder();
        // Send all output to the Appendable object sb
        Formatter formatter = new Formatter(sb, Locale.US);

        long s = Math.abs(milliseconds / 1000);
        long m = Math.abs(milliseconds % 1000);
        if (milliseconds > 0) {
            formatter.format("%d.%03ds", s, m);
        } else if (milliseconds == 0) {
            formatter.format("0");
        } else {
            formatter.format("-%d.%03ds", s, m);
        }
        return sb.toString();
    }
}

Related

  1. GetRawView(String string)
  2. getRoundedString(double value, int powerOf10)
  3. incrementAlpha(String suppliedPrefix, String lastNumber, int numberLength)
  4. listToString(List list, String separator)
  5. long2Mac(final long macAddress)
  6. msToHumanReadableDelta(long start)
  7. numberWithLeadingZeroes(int n, int totalChars)
  8. showVxlanHeaderOutput()
  9. substitution(Formatter formatter, int flags, int width, int precision, StringBuilder obj)