Here you can find the source of formatDuration(int seconds)
public static String formatDuration(int seconds)
//package com.java2s; //License from project: Open Source License public class Main { public static String formatDuration(int seconds) { if (seconds == 0) { return ""; }/*w ww. j a v a 2 s . c o m*/ int days = seconds / 86400; int hours = (seconds % 86400) / 3600; int mins = (seconds % 3600) / 60; int secs = seconds % 60; StringBuffer buf = new StringBuffer(); if (days > 0) { buf.append(days).append("d "); } if (hours > 0) { buf.append(hours).append("h "); } if (mins > 0) { buf.append(mins).append("m "); } if (secs > 0) { buf.append(secs).append("s "); } buf.setLength(buf.length() - 1); // trim return buf.toString(); } }