void formatFractionalSeconds ( StringBuilder b , ZonedDateTime d , int width ) { // format up to 9 digits at nanosecond resolution. int nano = d . getNano ( ) ; int f = 100000000 ; while ( width > 0 && f > 0 ) { int digit = nano / f ; nano -= ( digit * f ) ; f /= 10 ; b . append ( digit ) ; width -- ; } // fill out any trailing zeros if any are requested while ( width > 0 ) { b . append ( ' ' ) ; width -- ; } }
Format fractional seconds up to N digits .