public static String timeToReadable ( long millis , String suffix ) { StringBuilder builder = new StringBuilder ( ) ; boolean haveDays = false ; if ( millis > ONE_DAY ) { millis = handleTime ( builder , millis , ONE_DAY , "day" , "s" ) ; haveDays = true ; } boolean haveHours = false ; if ( millis >= ONE_HOUR ) { millis = handleTime ( builder , millis , ONE_HOUR , "h" , "" ) ; haveHours = true ; } if ( ( ! haveDays || ! haveHours ) && millis >= ONE_MINUTE ) { millis = handleTime ( builder , millis , ONE_MINUTE , "min" , "" ) ; } if ( ! haveDays && ! haveHours && millis >= ONE_SECOND ) { /*millis =*/ handleTime ( builder , millis , ONE_SECOND , "s" , "" ) ; } if ( builder . length ( ) > 0 ) { // cut off trailing ", " builder . setLength ( builder . length ( ) - 2 ) ; builder . append ( suffix ) ; } return builder . toString ( ) ; }
Format the given number of milliseconds as readable string optionally appending a suffix .