public String format ( long timestamp ) { // If the format is unknown, use the default formatter. if ( invalidFormat ) { return formatter . format ( timestamp ) ; } try { long delta = timestamp - refTimestamp ; // If we need to reformat if ( delta >= pdiff || delta < ndiff ) { StringBuffer refTime = new StringBuffer ( ) ; refTimestamp = timestamp ; formatter . format ( timestamp , refTime , position ) ; refMilli = Long . parseLong ( refTime . substring ( position . getBeginIndex ( ) , position . getEndIndex ( ) ) ) ; refBeginning = refTime . substring ( 0 , position . getBeginIndex ( ) ) ; refEnding = refTime . substring ( position . getEndIndex ( ) ) ; pdiff = 1000 - refMilli ; ndiff = - refMilli ; return refTime . toString ( ) ; } else { StringBuffer sb = new StringBuffer ( ) ; long newMilli = delta + refMilli ; if ( newMilli >= 100 ) sb . append ( refBeginning ) . append ( newMilli ) . append ( refEnding ) ; else if ( newMilli >= 10 ) sb . append ( refBeginning ) . append ( ' ' ) . append ( newMilli ) . append ( refEnding ) ; else sb . append ( refBeginning ) . append ( "00" ) . append ( newMilli ) . append ( refEnding ) ; return sb . toString ( ) ; } } catch ( Exception e ) { // Throw FFDC in case anything goes wrong // Still generate the date via the SimpleDateFormat invalidFormat = true ; return formatter . format ( timestamp ) ; } }
Formats a timestamp