Java Utililty Methods Duration

List of utility methods to do Duration

Description

The list of methods to do Duration are organized into topic(s).

Method

StringprintDuration(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) {
...
DateFormatroundedRelativeFormat()
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");
...