Here you can find the source of formatTime(int seconds)
Parameter | Description |
---|---|
seconds | The number of seconds. |
public static String formatTime(int seconds)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w.j a v a 2s .c o m*/ * Formats the time information as a string. * @param seconds The number of seconds. * @return A formatted string. */ public static String formatTime(int seconds) { StringBuilder result = new StringBuilder(); int days, hrs, mins, secs; days = seconds / (60 * 60 * 24); seconds %= 60 * 60 * 24; hrs = seconds / (60 * 60); seconds %= 60 * 60; mins = seconds / 60; secs = seconds % 60; if (days > 0) result.append(days).append("d "); if (hrs > 0) result.append(hrs).append("h "); if (mins > 0) result.append(mins).append("m "); if (secs > 0) result.append(secs).append("s "); return result.toString(); } }