Class InstantFormatter


  • public final class InstantFormatter
    extends java.lang.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 Detail

      • format

        public java.lang.String format​(Instant instant)
      • format

        public void format​(Instant instant,
                           java.lang.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 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 java.lang.Class<?> getInternalImplementationClass()
      • patternSupported

        private static boolean patternSupported​(java.lang.String pattern,
                                                java.util.Locale locale,
                                                java.util.TimeZone timeZone,
                                                InstantFormatter.Formatter formatter)
        Checks if the provided formatter output matches with the one generated by DateTimeFormatter.