String
printDuration(double uptime) Prints the duration in a human readable format as X days Y hours Z minutes etc.
NumberFormat fmtI = new DecimalFormat("###,###", new DecimalFormatSymbols(Locale.ENGLISH));
NumberFormat fmtD = new DecimalFormat("###,##0.000", new DecimalFormatSymbols(Locale.ENGLISH));
uptime /= 1000;
if (uptime < 60) {
return fmtD.format(uptime) + " seconds";
uptime /= 60;
if (uptime < 60) {
...
DateFormat
roundedRelativeFormat() rounded Relative Format
return new DateFormat() {
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
Date now = new Date();
long secondsDiff = (now.getTime() - date.getTime()) / 1000;
if (secondsDiff <= 1) {
return toAppendTo.append("1 second ago");
} else if (secondsDiff < 60) {
return toAppendTo.append(secondsDiff).append(" seconds ago");
...