Here you can find the source of toTimeString(long millis)
public static String toTimeString(long millis)
//package com.java2s; /*//from w ww . java 2 s .c o m * #%L * Intuit Tank Api * %% * Copyright (C) 2011 - 2015 Intuit Inc. * %% * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * #L% */ public class Main { public static String toTimeString(long millis) { int ms = (int) (millis % 1000); int sec = (int) (Math.floor(millis / 1000)) % 60; int min = (int) (Math.floor(millis / (1000 * 60))) % 60; int hours = (int) (Math.floor(millis / (1000 * 60 * 60))) % 24; int days = (int) (Math.floor(millis / (1000 * 60 * 60 * 24))); StringBuilder sb = new StringBuilder(); if (days > 0) { sb.append(days).append("d"); } if (hours > 0) { if (sb.length() > 0) { sb.append(' '); } sb.append(hours).append("h"); } if (min > 0) { if (sb.length() > 0) { sb.append(' '); } sb.append(min).append("m"); } if (sec > 0) { if (sb.length() > 0) { sb.append(' '); } sb.append(sec).append("s"); } if (ms > 0) { if (sb.length() > 0) { sb.append(' '); } sb.append(ms).append("ms"); } if (sb.length() == 0) { sb.append('0'); } return sb.toString(); } }