Here you can find the source of toDaySecondDifference(long difference)
public static String toDaySecondDifference(long difference)
//package com.java2s; //License from project: Open Source License public class Main { public static String toDaySecondDifference(long difference) { difference *= difference > 0 ? .001 : -.001; if (difference == 0) { return "0 seconds"; }//from w w w . j av a 2 s .c o m StringBuilder ret = new StringBuilder(); difference = append(ret, difference, 60 * 60 * 24, "day"); difference = append(ret, difference, 60 * 60, "hour"); difference = append(ret, difference, 60, "minute"); append(ret, difference, 1, "second"); return ret.toString(); } private static long append(StringBuilder sb, long val, long min, String desc) { long v = val / min; if (v > 0) { if (sb.length() > 0) { sb.append(" "); } sb.append(v).append(" ").append(desc); if (v > 1) { sb.append("s"); } } return val - v * min; } }