Here you can find the source of millisToShortDHMS(long duration)
public static String millisToShortDHMS(long duration)
//package com.java2s; /*/*from ww w .j a va 2s . co m*/ * This file is part of SWADroid. * * Copyright (C) 2010 Juan Miguel Boyero Corral <juanmi1982@gmail.com> * * SWADroid is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SWADroid is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SWADroid. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Locale; public class Main { public final static long ONE_SECOND = 1000; public final static long SECONDS = 60; public final static long MINUTES = 60; public final static long HOURS = 24; /** * converts time (in milliseconds) to human-readable format * "<dd:>hh:mm:ss" */ public static String millisToShortDHMS(long duration) { String res = ""; duration /= ONE_SECOND; int seconds = (int) (duration % SECONDS); duration /= SECONDS; int minutes = (int) (duration % MINUTES); duration /= MINUTES; int hours = (int) (duration % HOURS); int days = (int) (duration / HOURS); if (days == 0) { res = String.format(Locale.getDefault(), "%02d:%02d:%02d", hours, minutes, seconds); } else { res = String.format(Locale.getDefault(), "%dd%02d:%02d:%02d", days, hours, minutes, seconds); } return res; } }