public String getAsString ( EnumSet < TimeUnit > timeUnits ) { StringBuilder sb = new StringBuilder ( ) ; EnumMap < TimeUnit , Timespan > canonicalTimespans = getAsTimespans ( timeUnits ) ; for ( TimeUnit timeUnit : TIME_UNIT_ORDER ) { if ( canonicalTimespans . containsKey ( timeUnit ) ) { long duration = canonicalTimespans . get ( timeUnit ) . getDuration ( ) ; if ( duration > 0 ) { sb . append ( duration ) . append ( timeUnit . getDisplayChar ( ) ) ; } } } if ( sb . length ( ) == 0 ) { sb . append ( 0 ) ; if ( timeUnits . contains ( getTimeUnit ( ) ) ) sb . append ( getTimeUnit ( ) . getDisplayChar ( ) ) ; } return sb . toString ( ) ; }
Returns a string representing this timespan expressed with the units provided .