Class InstantFormatter

java.lang.Object
org.apache.logging.log4j.layout.template.json.util.InstantFormatter

public final class InstantFormatter extends Object
A composite Instant formatter trying to employ either FixedDateFormat, FastDateFormat, or DateTimeFormatter in the given order due to performance reasons.

Note that FixedDateFormat and FastDateFormat only support millisecond precision. If the pattern asks for a higher precision, DateTimeFormatter will be employed, which is significantly slower.

  • Method Details

    • format

      public String format(Instant instant)
    • format

      public void format(Instant instant, StringBuilder stringBuilder)
    • isInstantMatching

      public boolean isInstantMatching(Instant instant1, Instant instant2)
      Checks if the given Instants are equal from the point of view of the employed formatter.

      This method should be preferred over

      invalid reference
      Instant#equals(Object)
      . For instance, FixedDateFormat and FastDateFormat discard nanoseconds, hence, from their point of view, two different Instants are equal if they match up to millisecond precision.
    • getInternalImplementationClass

      public Class<?> getInternalImplementationClass()
    • newBuilder

      public static InstantFormatter.Builder newBuilder()