Here you can find the source of getTimeStr(final long millis)
public static String getTimeStr(final long millis)
//package com.java2s; /**//from www . j a va 2 s.c o 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 * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * 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.text.DecimalFormat; import java.util.concurrent.TimeUnit; public class Main { private static final DecimalFormat secondFormat = new DecimalFormat("#.##"); public static String getTimeStr(final long millis) { long minutes = TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)); long hours = TimeUnit.MILLISECONDS.toHours(millis); StringBuilder b = new StringBuilder(); b.append(hours == 0 ? "" : String.valueOf(hours) + "h"); b.append(minutes == 0 ? "" : String.valueOf(minutes) + "m"); long seconds = millis - TimeUnit.MINUTES.toMillis(TimeUnit.MILLISECONDS.toMinutes(millis)); b.append(secondFormat.format(seconds / 1000.0) + "s"); return b.toString(); } }