Class SimpleFormatter<T>
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionstatic SimpleFormatter<Moment>
Defines the RFC-1123-format which is for example used in mail headers (technical internet-timestamp). -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determines all global format attributes if available.int
hashCode()
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.static SimpleFormatter<PlainDate>
ofDateStyle(FormatStyle style, Locale locale)
Constructs a style-based formatter for plain date objects.static SimpleFormatter<PlainDate>
ofDateStyle(DisplayMode style, Locale locale)
Deprecated.static SimpleFormatter<Moment>
ofMomentPattern(String pattern, Locale locale, TZID tzid)
Constructs a pattern-based formatter for global timestamp objects (moments).static SimpleFormatter<Moment>
ofMomentStyle(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, TZID tzid)
Constructs a style-based formatter for global timestamp objects (moments).static SimpleFormatter<Moment>
ofMomentStyle(DisplayMode dateStyle, DisplayMode timeStyle, Locale locale, TZID tzid)
Deprecated.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.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.static SimpleFormatter<PlainTimestamp>
ofTimestampStyle(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale)
Constructs a style-based formatter for plain timestamp objects.static SimpleFormatter<PlainTimestamp>
ofTimestampStyle(DisplayMode dateStyle, DisplayMode timeStyle, Locale locale)
Deprecated.static SimpleFormatter<PlainTime>
ofTimeStyle(FormatStyle style, Locale locale)
Constructs a style-based formatter for plain time objects.static SimpleFormatter<PlainTime>
ofTimeStyle(DisplayMode style, Locale locale)
Deprecated.parse(CharSequence text)
Interpretes given text as chronological entity.parse(CharSequence text, RawValues rawValues)
Interpretes given text as chronological entity and updates given raw values.Prints given chronological entity as formatted text.Creates a copy of this formatter with given locale.Sets the leniency mode.withTimezone(String tzid)
Equivalent towithTimezone(Timezone.of(tzid).getID())
.withTimezone(TZID tzid)
Creates a copy of this formatter with given timezone id which shall be used in formatting or parsing.Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.time4j.format.TemporalFormatter
format
-
Field Details
-
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
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 bySimpleDateFormat
locale
- locale setting- Returns:
- format object for formatting
PlainDate
-objects using given locale - Since:
- 5.0
-
ofDateStyle
Deprecated.Constructs a style-based formatter for plain date objects.
- Parameters:
style
- format stylelocale
- format locale- Returns:
- new
SimpleFormatter
-instance - Throws:
IllegalStateException
- if no localized format pattern can be retrieved- Since:
- 5.0
-
ofDateStyle
Constructs a style-based formatter for plain date objects.
- Parameters:
style
- format stylelocale
- format locale- Returns:
- new
SimpleFormatter
-instance - Throws:
IllegalStateException
- if no localized format pattern can be retrieved- Since:
- 5.8
-
ofTimePattern
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 bySimpleDateFormat
locale
- locale setting- Returns:
- format object for formatting
PlainTime
-objects using given locale - Since:
- 5.0
-
ofTimeStyle
Deprecated.Constructs a style-based formatter for plain time objects.
- Parameters:
style
- format stylelocale
- format locale- Returns:
- new
SimpleFormatter
-instance - Throws:
IllegalStateException
- if no localized format pattern can be retrieved- Since:
- 5.0
-
ofTimeStyle
Constructs a style-based formatter for plain time objects.
- Parameters:
style
- format stylelocale
- format locale- Returns:
- new
SimpleFormatter
-instance - Throws:
IllegalStateException
- if no localized format pattern can be retrieved- Since:
- 5.8
-
ofTimestampPattern
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 bySimpleDateFormat
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)Deprecated.Constructs a style-based formatter for plain timestamp objects.
- Parameters:
dateStyle
- format style for the date componenttimeStyle
- format style for the time componentlocale
- 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 componenttimeStyle
- format style for the time componentlocale
- format locale- Returns:
- new
SimpleFormatter
-instance - Throws:
IllegalStateException
- if no localized format pattern can be retrieved- Since:
- 5.8
-
ofMomentPattern
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 patternlocale
- format localetzid
- 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)Deprecated.Constructs a style-based formatter for global timestamp objects (moments).
- Parameters:
dateStyle
- format style for the date componenttimeStyle
- format style for the time componentlocale
- format localetzid
- 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 componenttimeStyle
- format style for the time componentlocale
- format localetzid
- timezone id- Returns:
- new
SimpleFormatter
-instance - Throws:
IllegalStateException
- if no localized format pattern can be retrieved- Since:
- 5.8
-
print
Description copied from interface:TemporalFormatter
Prints given chronological entity as formatted text.
- Specified by:
print
in interfaceTemporalFormatter<T>
- Parameters:
formattable
- object to be formatted- Returns:
- formatted text
-
parse
Description copied from interface:TemporalFormatter
Interpretes given text as chronological entity.
- Specified by:
parse
in interfaceTemporalFormatter<T>
- Parameters:
text
- text to be parsed- Returns:
- parse result
- Throws:
ParseException
- if the text is not parseable
-
parse
Description copied from interface:TemporalFormatter
Interpretes given text as chronological entity and updates given raw values.
- Specified by:
parse
in interfaceTemporalFormatter<T>
- Parameters:
text
- text to be parsedrawValues
- holder for raw values (always as new instance)- Returns:
- parsed result
- Throws:
ParseException
- if parsing does not work
-
withTimezone
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 interfaceTemporalFormatter<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
Description copied from interface:TemporalFormatter
Equivalent to
withTimezone(Timezone.of(tzid).getID())
.- Specified by:
withTimezone
in interfaceTemporalFormatter<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
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 interfaceTemporalFormatter<T>
- Parameters:
locale
- new language and country configuration- Returns:
- changed copy with given language and localized symbols while this instance remains unaffected
-
with
Description copied from interface:TemporalFormatter
Sets the leniency mode.
By default any temporal formatter is smart.
- Specified by:
with
in interfaceTemporalFormatter<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
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 interfaceTemporalFormatter<T>
- Returns:
- attribute query
-
equals
-
hashCode
public int hashCode()
-
ofDateStyle(FormatStyle, Locale)