public static CharSequence duration(long duration, TimeUnit units, TimeUnitFormat unitFormat) { return appendDuration(new StringBuilder(), duration, units, unitFormat); }
public static StringBuilder appendRelativeTimestamp(StringBuilder sb, long when, long current, TimeUnitFormat format) { checkArgument(when > 0); checkArgument(current > 0); SimpleDateFormat iso8601 = new SimpleDateFormat(TIMESTAMP_FORMAT); sb.append(iso8601.format(new Date(when))); long diff = Math.abs(when - current); sb.append(" ("); appendDuration(sb, diff, MILLISECONDS, format); sb.append(' '); sb.append(when < current ? "ago" : "in the future"); sb.append(')'); return sb; }