Class SimpleFormatter<T>

java.lang.Object
net.time4j.format.platform.SimpleFormatter<T>
All Implemented Interfaces:
TemporalFormatter<T>

public final class SimpleFormatter<T> extends Object implements TemporalFormatter<T>

A temporal formatter which uses platform specific resources based on SimpleDateFormat.

The only supported types are:

  • PlainDate
  • PlainTime
  • PlainTimestamp
  • Moment
Since:
5.0
Author:
Meno Hochschild
  • Field Details

    • RFC_1123

      public static final SimpleFormatter<Moment> RFC_1123

      Defines the RFC-1123-format which is for example used in mail headers (technical internet-timestamp).

      Equivalent to the pattern "[EEE, ]d MMM yyyy HH:mm[:ss] XX" where the timezone offset XX is modified such that in case of zero offset the expression "GMT" is preferred. "UT" or "Z" will be accepted as zero offset, too. The text elements will always be interpreted in English and are case-insensitive. If no extra timezone is specified then this formatter will use the timezone UTC as default for printing.

      Note: In contrast to the RFC-1123-standard this constant does not support military timezone abbreviations (A-Y) or north-american timezone names (EST, EDT, CST, CDT, MST, MDT, PST, PDT).

  • Method Details

    • ofDatePattern

      public static SimpleFormatter<PlainDate> ofDatePattern(String pattern, Locale locale)

      Creates a new formatter which uses the given pattern and locale for formatting and parsing plain dates.

      The pattern is only validated during printing or parsing.

      Parameters:
      pattern - format definition as pattern as defined by SimpleDateFormat
      locale - locale setting
      Returns:
      format object for formatting PlainDate-objects using given locale
      Since:
      5.0
    • ofDateStyle

      @Deprecated public static SimpleFormatter<PlainDate> ofDateStyle(DisplayMode style, Locale locale)

      Constructs a style-based formatter for plain date objects.

      Parameters:
      style - format style
      locale - format locale
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.0
    • ofDateStyle

      public static SimpleFormatter<PlainDate> ofDateStyle(FormatStyle style, Locale locale)

      Constructs a style-based formatter for plain date objects.

      Parameters:
      style - format style
      locale - format locale
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.8
    • ofTimePattern

      public static SimpleFormatter<PlainTime> ofTimePattern(String pattern, Locale locale)

      Creates a new formatter which uses the given pattern and locale for formatting and parsing plain times.

      The pattern is only validated during printing or parsing.

      Parameters:
      pattern - format definition as pattern as defined by SimpleDateFormat
      locale - locale setting
      Returns:
      format object for formatting PlainTime-objects using given locale
      Since:
      5.0
    • ofTimeStyle

      @Deprecated public static SimpleFormatter<PlainTime> ofTimeStyle(DisplayMode style, Locale locale)

      Constructs a style-based formatter for plain time objects.

      Parameters:
      style - format style
      locale - format locale
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.0
    • ofTimeStyle

      public static SimpleFormatter<PlainTime> ofTimeStyle(FormatStyle style, Locale locale)

      Constructs a style-based formatter for plain time objects.

      Parameters:
      style - format style
      locale - format locale
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.8
    • ofTimestampPattern

      public static SimpleFormatter<PlainTimestamp> ofTimestampPattern(String pattern, Locale locale)

      Creates a new formatter which uses the given pattern and locale for formatting and parsing plain timestamps.

      The pattern is only validated during printing or parsing.

      Parameters:
      pattern - format definition as pattern as defined by SimpleDateFormat
      locale - locale setting
      Returns:
      format object for formatting PlainTimestamp-objects using given locale
      Since:
      5.0
    • ofTimestampStyle

      @Deprecated public static SimpleFormatter<PlainTimestamp> ofTimestampStyle(DisplayMode dateStyle, DisplayMode timeStyle, Locale locale)

      Constructs a style-based formatter for plain timestamp objects.

      Parameters:
      dateStyle - format style for the date component
      timeStyle - format style for the time component
      locale - format locale
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.0
    • ofTimestampStyle

      public static SimpleFormatter<PlainTimestamp> ofTimestampStyle(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale)

      Constructs a style-based formatter for plain timestamp objects.

      Parameters:
      dateStyle - format style for the date component
      timeStyle - format style for the time component
      locale - format locale
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.8
    • ofMomentPattern

      public static SimpleFormatter<Moment> ofMomentPattern(String pattern, Locale locale, TZID tzid)

      Constructs a pattern-based formatter for global timestamp objects (moments).

      The given timezone parameter can help to compensate missing timezone or offset informations in input or to resolve possibly ambivalent timezone names in input.

      Parameters:
      pattern - format pattern
      locale - format locale
      tzid - timezone id
      Returns:
      new format object for formatting Moment-objects using given locale and timezone
      Throws:
      IllegalArgumentException - if resolving of pattern fails or the timezone cannot be loaded
      Since:
      5.0
    • ofMomentStyle

      @Deprecated public static SimpleFormatter<Moment> ofMomentStyle(DisplayMode dateStyle, DisplayMode timeStyle, Locale locale, TZID tzid)

      Constructs a style-based formatter for global timestamp objects (moments).

      Parameters:
      dateStyle - format style for the date component
      timeStyle - format style for the time component
      locale - format locale
      tzid - timezone id
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.0
    • ofMomentStyle

      public static SimpleFormatter<Moment> ofMomentStyle(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, TZID tzid)

      Constructs a style-based formatter for global timestamp objects (moments).

      Parameters:
      dateStyle - format style for the date component
      timeStyle - format style for the time component
      locale - format locale
      tzid - timezone id
      Returns:
      new SimpleFormatter-instance
      Throws:
      IllegalStateException - if no localized format pattern can be retrieved
      Since:
      5.8
    • print

      public String print(T formattable)
      Description copied from interface: TemporalFormatter

      Prints given chronological entity as formatted text.

      Specified by:
      print in interface TemporalFormatter<T>
      Parameters:
      formattable - object to be formatted
      Returns:
      formatted text
    • parse

      public T parse(CharSequence text) throws ParseException
      Description copied from interface: TemporalFormatter

      Interpretes given text as chronological entity.

      Specified by:
      parse in interface TemporalFormatter<T>
      Parameters:
      text - text to be parsed
      Returns:
      parse result
      Throws:
      ParseException - if the text is not parseable
    • parse

      public T parse(CharSequence text, RawValues rawValues) throws ParseException
      Description copied from interface: TemporalFormatter

      Interpretes given text as chronological entity and updates given raw values.

      Specified by:
      parse in interface TemporalFormatter<T>
      Parameters:
      text - text to be parsed
      rawValues - holder for raw values (always as new instance)
      Returns:
      parsed result
      Throws:
      ParseException - if parsing does not work
    • withTimezone

      public TemporalFormatter<T> withTimezone(TZID tzid)
      Description copied from interface: TemporalFormatter

      Creates a copy of this formatter with given timezone id which shall be used in formatting or parsing.

      The timezone is in most cases only relevant for the type Moment. When formatting the timezone helps to convert the UTC value into a zonal representation. When parsing the timezone serves as replacement value if the formatted text does not contain any timezone.

      Specified by:
      withTimezone in interface TemporalFormatter<T>
      Parameters:
      tzid - timezone id
      Returns:
      changed copy with the new or changed attribute while this instance remains unaffected
      See Also:
      Attributes.TIMEZONE_ID
    • withTimezone

      public TemporalFormatter<T> withTimezone(String tzid)
      Description copied from interface: TemporalFormatter
      Specified by:
      withTimezone in interface TemporalFormatter<T>
      Parameters:
      tzid - timezone id
      Returns:
      changed copy with the new or changed attribute while this instance remains unaffected
      See Also:
      TemporalFormatter.withTimezone(TZID), Attributes.TIMEZONE_ID
    • with

      public TemporalFormatter<T> with(Locale locale)
      Description copied from interface: TemporalFormatter

      Creates a copy of this formatter with given locale.

      Note that changing the locale cannot change the inner structure of this formatter even if the structure is no longer appropriate for given locale. An example is the English AM/PM-pattern which will be preserved even if the language changes from English to German.

      Specified by:
      with in interface TemporalFormatter<T>
      Parameters:
      locale - new language and country configuration
      Returns:
      changed copy with given language and localized symbols while this instance remains unaffected
    • with

      public TemporalFormatter<T> with(Leniency leniency)
      Description copied from interface: TemporalFormatter

      Sets the leniency mode.

      By default any temporal formatter is smart.

      Specified by:
      with in interface TemporalFormatter<T>
      Parameters:
      leniency - determines how strict the parser should be
      Returns:
      changed copy with the new or changed attribute while this instance remains unaffected
      See Also:
      Attributes.LENIENCY
    • getAttributes

      public AttributeQuery getAttributes()
      Description copied from interface: TemporalFormatter

      Determines all global format attributes if available.

      Global attributes are valid for the whole formatter. Sectional attributes which might exist and control the behaviour of only a part of the formatter cannot be overridden.

      Specified by:
      getAttributes in interface TemporalFormatter<T>
      Returns:
      attribute query
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object