Here you can find the source of secondsToDHMSString(double seconds)
public static String secondsToDHMSString(double seconds)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String secondsToDHMSString(double seconds) { if (seconds < 60) { return doubleToString(seconds, 2, 2) + 's'; }/*w w w .j a v a2 s .c o m*/ long secs = (int) (seconds); long mins = secs / 60; long hours = mins / 60; long days = hours / 24; secs %= 60; mins %= 60; hours %= 24; StringBuilder result = new StringBuilder(); if (days > 0) { result.append(days); result.append('d'); } if ((hours > 0) || (days > 0)) { result.append(hours); result.append('h'); } if ((hours > 0) || (days > 0) || (mins > 0)) { result.append(mins); result.append('m'); } result.append(secs); result.append('s'); return result.toString(); } public static String doubleToString(double value, int fractionDigits) { return doubleToString(value, 0, fractionDigits); } public static String doubleToString(double value, int minFractionDigits, int maxFractionDigits) { DecimalFormat numberFormat = new DecimalFormat(); numberFormat.setMinimumFractionDigits(minFractionDigits); numberFormat.setMaximumFractionDigits(maxFractionDigits); return numberFormat.format(value); } }