Here you can find the source of formatInterval(long interval)
Parameter | Description |
---|---|
interval | in seconds. |
public static String formatInterval(long interval)
//package com.java2s; public class Main { /**//from ww w . j a v a2 s . co m * Returns human readable representation of interval value in days, hours etc. * * @param interval in seconds. * @return human readable interval specification. */ public static String formatInterval(long interval) { long days = interval / (24 * 60 * 60); interval -= days * 24 * 60 * 60; long hours = interval / (60 * 60); interval -= hours * 60 * 60; long minutes = interval / 60; interval -= minutes * 60; long seconds = interval; StringBuffer buff = new StringBuffer(); if (days > 0) { buff.append(days).append(" days, "); } if (days > 0 || hours > 0) { buff.append(hours).append(" hours, "); } if (days > 0 || hours > 0 || minutes > 0) { buff.append(minutes).append(" minutes, "); } buff.append(seconds).append(" seconds"); return buff.toString(); } }