public static String formatDuration(long duration){
  StringBuilder result=new StringBuilder();
  long remainingDuration=duration;
  if (remainingDuration == 0) {
    result.append("0 Milliseconds");
  }
 else {
    remainingDuration=processDuration(remainingDuration,MILLIS_PER_DAY,"Day",result,false);
    remainingDuration=processDuration(remainingDuration,MILLIS_PER_HOUR,"Hour",result,false);
    remainingDuration=processDuration(remainingDuration,MILLIS_PER_MINUTE,"Minute",result,false);
    remainingDuration=processDuration(remainingDuration,MILLIS_PER_SECOND,"Second",result,false);
    long milliSeconds=remainingDuration;
    if (milliSeconds > 0) {
      processDuration(remainingDuration,1,"Millisecond",result,true);
    }
  }
  return result.toString();
}

public static String formatDuration ( long duration ) { StringBuilder result = new StringBuilder ( ) ; long remainingDuration = duration ; if ( remainingDuration == 0 ) { result . append ( "0 Milliseconds" ) ; } else { remainingDuration = processDuration ( remainingDuration , MILLIS_PER_DAY , "Day" , result , false ) ; remainingDuration = processDuration ( remainingDuration , MILLIS_PER_HOUR , "Hour" , result , false ) ; remainingDuration = processDuration ( remainingDuration , MILLIS_PER_MINUTE , "Minute" , result , false ) ; remainingDuration = processDuration ( remainingDuration , MILLIS_PER_SECOND , "Second" , result , false ) ; long milliSeconds = remainingDuration ; if ( milliSeconds > 0 ) { processDuration ( remainingDuration , 1 , "Millisecond" , result , true ) ; } } return result . toString ( ) ; }
formats a " total milliseconds " duration .
