Here you can find the source of millisToHumanTime(long milliseconds)
Parameter | Description |
---|---|
milliseconds | a time in milliseconds |
public static String millisToHumanTime(long milliseconds)
//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(); } }