static DateFormat getBasicDateFormatter ( ) { String pattern ; int patternLength ; int endOfSecsIndex ; // Retrieve a standard Java DateFormat object with desired format. DateFormat formatter = DateFormat . getDateTimeInstance ( DateFormat . SHORT , DateFormat . MEDIUM ) ; if ( formatter instanceof SimpleDateFormat ) { // Retrieve the pattern from the formatter, since we will need to modify it. SimpleDateFormat sdFormatter = ( SimpleDateFormat ) formatter ; pattern = sdFormatter . toPattern ( ) ; // Append milliseconds and timezone after seconds patternLength = pattern . length ( ) ; endOfSecsIndex = pattern . lastIndexOf ( ' ' ) + 1 ; String newPattern = pattern . substring ( 0 , endOfSecsIndex ) + ":SSS z" ; if ( endOfSecsIndex < patternLength ) newPattern += pattern . substring ( endOfSecsIndex , patternLength ) ; // 0-23 hour clock (get rid of any other clock formats and am/pm) newPattern = newPattern . replace ( ' ' , ' ' ) ; newPattern = newPattern . replace ( ' ' , ' ' ) ; newPattern = newPattern . replace ( ' ' , ' ' ) ; newPattern = newPattern . replace ( ' ' , ' ' ) ; newPattern = newPattern . trim ( ) ; sdFormatter . applyPattern ( newPattern ) ; formatter = sdFormatter ; } else { formatter = new SimpleDateFormat ( "yy.MM.dd HH:mm:ss:SSS z" ) ; } // PK13288 Start if ( sysTimeZone != null ) { formatter . setTimeZone ( sysTimeZone ) ; } // PK13288 End. return formatter ; }
Return a DateFormat object that can be used to format timestamps in the System . out System . err and TraceOutput logs .