private static DateTimeFormatter createFormatterForPattern ( String pattern ) { if ( pattern == null || pattern . length ( ) == 0 ) { throw new IllegalArgumentException ( "Invalid pattern specification" ) ; } DateTimeFormatter formatter = cPatternCache . get ( pattern ) ; if ( formatter == null ) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder ( ) ; parsePatternTo ( builder , pattern ) ; formatter = builder . toFormatter ( ) ; if ( cPatternCache . size ( ) < PATTERN_CACHE_SIZE ) { // the size check is not locked against concurrent access, // but is accepted to be slightly off in contention scenarios. DateTimeFormatter oldFormatter = cPatternCache . putIfAbsent ( pattern , formatter ) ; if ( oldFormatter != null ) { formatter = oldFormatter ; } } } return formatter ; }
Select a format from a custom pattern .