Enum NamedInstantPattern
- java.lang.Object
-
- java.lang.Enum<NamedInstantPattern>
-
- org.apache.logging.log4j.core.pattern.NamedInstantPattern
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<NamedInstantPattern>
@NullMarked public enum NamedInstantPattern extends java.lang.Enum<NamedInstantPattern>
Represents named date & time patterns for formatting log timestamps.- Since:
- 2.26.0
- See Also:
DatePatternConverter
-
-
Enum Constant Summary
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringlegacyPatternprivate java.lang.Stringpattern
-
Constructor Summary
Constructors Modifier Constructor Description privateNamedInstantPattern(java.lang.String pattern)privateNamedInstantPattern(java.lang.String pattern, java.lang.String legacyPattern)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.StringgetLegacyPattern()Returns the legacyFixedDateFormatpattern associated with this named pattern.java.lang.StringgetPattern()Returns the date-time pattern string compatible withDateTimeFormatterthat is associated with this named pattern.static NamedInstantPatternvalueOf(java.lang.String name)Returns the enum constant of this type with the specified name.static NamedInstantPattern[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
ABSOLUTE
public static final NamedInstantPattern ABSOLUTE
-
ABSOLUTE_MICROS
public static final NamedInstantPattern ABSOLUTE_MICROS
-
ABSOLUTE_NANOS
public static final NamedInstantPattern ABSOLUTE_NANOS
-
ABSOLUTE_PERIOD
public static final NamedInstantPattern ABSOLUTE_PERIOD
-
COMPACT
public static final NamedInstantPattern COMPACT
-
DATE
public static final NamedInstantPattern DATE
-
DATE_PERIOD
public static final NamedInstantPattern DATE_PERIOD
-
DEFAULT
public static final NamedInstantPattern DEFAULT
-
DEFAULT_MICROS
public static final NamedInstantPattern DEFAULT_MICROS
-
DEFAULT_NANOS
public static final NamedInstantPattern DEFAULT_NANOS
-
DEFAULT_PERIOD
public static final NamedInstantPattern DEFAULT_PERIOD
-
ISO8601_BASIC
public static final NamedInstantPattern ISO8601_BASIC
-
ISO8601_BASIC_PERIOD
public static final NamedInstantPattern ISO8601_BASIC_PERIOD
-
ISO8601
public static final NamedInstantPattern ISO8601
-
ISO8601_OFFSET_DATE_TIME_HH
public static final NamedInstantPattern ISO8601_OFFSET_DATE_TIME_HH
-
ISO8601_OFFSET_DATE_TIME_HHMM
public static final NamedInstantPattern ISO8601_OFFSET_DATE_TIME_HHMM
-
ISO8601_OFFSET_DATE_TIME_HHCMM
public static final NamedInstantPattern ISO8601_OFFSET_DATE_TIME_HHCMM
-
ISO8601_PERIOD
public static final NamedInstantPattern ISO8601_PERIOD
-
ISO8601_PERIOD_MICROS
public static final NamedInstantPattern ISO8601_PERIOD_MICROS
-
US_MONTH_DAY_YEAR2_TIME
public static final NamedInstantPattern US_MONTH_DAY_YEAR2_TIME
-
US_MONTH_DAY_YEAR4_TIME
public static final NamedInstantPattern US_MONTH_DAY_YEAR4_TIME
-
-
Method Detail
-
values
public static NamedInstantPattern[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (NamedInstantPattern c : NamedInstantPattern.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static NamedInstantPattern valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException- if this enum type has no constant with the specified namejava.lang.NullPointerException- if the argument is null
-
getPattern
public java.lang.String getPattern()
Returns the date-time pattern string compatible withDateTimeFormatterthat is associated with this named pattern.- Returns:
- the date-time pattern string for use with
DateTimeFormatter
-
getLegacyPattern
java.lang.String getLegacyPattern()
Returns the legacyFixedDateFormatpattern associated with this named pattern.If legacy formatters are enabled, output is produced for
FixedDateFormatandFastDateFormat. To convert theDateTimeFormatterto its legacy counterpart, the following transformations need to be applied:Pattern Differences Microseconds Nanoseconds Time-zone Legacy formatter directive nnnnnnnnnnnnnnnX,XX,XXXDateTimeFormatterdirectiveSSSSSSSSSSSSSSSx,xx,xxxRationale
-
Legacy formatters are largely compatible with the
SimpleDateFormatspecification, but introduce a customnpattern letter, unique to Log4j, to represent sub-millisecond precision. Thisnis not part of the standardSimpleDateFormat.In legacy formatters, repeating
nincreases the precision, similar to how repeatedSis used for fractional seconds inDateTimeFormatter.In contrast,
DateTimeFormatterinterpretsnas nano-of-second. In Java 17, bothnandNalways output nanosecond precision, regardless of the number of pattern letters. -
Legacy formatters use
X,XX, andXXXto format time zones as+00,+0000, or+00:00, followingSimpleDateFormatconventions. In contrast,DateTimeFormatteroutputsZfor zero-offset when usingX. To ensure numeric output for zero-offset (e.g.,+00), we usex,xx, orxxxinstead.
- Returns:
- the legacy pattern string as used in
FixedDateFormat.FixedFormat
-
-
-