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:
PlainDatePlainTimePlainTimestampMoment| Modifier and Type | Field and Description |
|---|---|
static SimpleFormatter<Moment> |
RFC_1123
Defines the RFC-1123-format which is for example used in mail headers (technical internet-timestamp).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
AttributeQuery |
getAttributes()
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(DisplayMode style,
Locale locale)
Deprecated.
|
static SimpleFormatter<PlainDate> |
ofDateStyle(FormatStyle style,
Locale locale)
Constructs a style-based formatter for plain date objects.
|
static SimpleFormatter<Moment> |
ofMomentPattern(String pattern,
Locale locale,
TZID tzid)
Constructs a pattern-based formatter for global timestamp objects (moments).
|
static SimpleFormatter<Moment> |
ofMomentStyle(DisplayMode dateStyle,
DisplayMode timeStyle,
Locale locale,
TZID tzid)
Deprecated.
|
static SimpleFormatter<Moment> |
ofMomentStyle(FormatStyle dateStyle,
FormatStyle timeStyle,
Locale locale,
TZID tzid)
Constructs a style-based formatter for global timestamp objects (moments).
|
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(DisplayMode dateStyle,
DisplayMode timeStyle,
Locale locale)
Deprecated.
|
static SimpleFormatter<PlainTimestamp> |
ofTimestampStyle(FormatStyle dateStyle,
FormatStyle timeStyle,
Locale locale)
Constructs a style-based formatter for plain timestamp objects.
|
static SimpleFormatter<PlainTime> |
ofTimeStyle(DisplayMode style,
Locale locale)
Deprecated.
|
static SimpleFormatter<PlainTime> |
ofTimeStyle(FormatStyle style,
Locale locale)
Constructs a style-based formatter for plain time objects.
|
T |
parse(CharSequence text)
Interpretes given text as chronological entity.
|
T |
parse(CharSequence text,
RawValues rawValues)
Interpretes given text as chronological entity and updates given raw values.
|
String |
print(T formattable)
Prints given chronological entity as formatted text.
|
TemporalFormatter<T> |
with(Leniency leniency)
Sets the leniency mode.
|
TemporalFormatter<T> |
with(Locale locale)
Creates a copy of this formatter with given locale.
|
TemporalFormatter<T> |
withTimezone(String tzid)
Equivalent to
withTimezone(Timezone.of(tzid).getID()). |
TemporalFormatter<T> |
withTimezone(TZID tzid)
Creates a copy of this formatter with given timezone id which
shall be used in formatting or parsing.
|
getClass, notify, notifyAll, toString, wait, wait, waitformatpublic 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).
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.
pattern - format definition as pattern as defined by SimpleDateFormatlocale - locale settingPlainDate-objects using given locale@Deprecated public static SimpleFormatter<PlainDate> ofDateStyle(DisplayMode style, Locale locale)
ofDateStyle(FormatStyle, Locale)Constructs a style-based formatter for plain date objects.
style - format stylelocale - format localeSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic static SimpleFormatter<PlainDate> ofDateStyle(FormatStyle style, Locale locale)
Constructs a style-based formatter for plain date objects.
style - format stylelocale - format localeSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic 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.
pattern - format definition as pattern as defined by SimpleDateFormatlocale - locale settingPlainTime-objects using given locale@Deprecated public static SimpleFormatter<PlainTime> ofTimeStyle(DisplayMode style, Locale locale)
ofTimeStyle(FormatStyle, Locale)Constructs a style-based formatter for plain time objects.
style - format stylelocale - format localeSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic static SimpleFormatter<PlainTime> ofTimeStyle(FormatStyle style, Locale locale)
Constructs a style-based formatter for plain time objects.
style - format stylelocale - format localeSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic 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.
pattern - format definition as pattern as defined by SimpleDateFormatlocale - locale settingPlainTimestamp-objects using given locale@Deprecated public static SimpleFormatter<PlainTimestamp> ofTimestampStyle(DisplayMode dateStyle, DisplayMode timeStyle, Locale locale)
ofTimestampStyle(FormatStyle, FormatStyle, Locale)Constructs a style-based formatter for plain timestamp objects.
dateStyle - format style for the date componenttimeStyle - format style for the time componentlocale - format localeSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic static SimpleFormatter<PlainTimestamp> ofTimestampStyle(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale)
Constructs a style-based formatter for plain timestamp objects.
dateStyle - format style for the date componenttimeStyle - format style for the time componentlocale - format localeSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic 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.
pattern - format patternlocale - format localetzid - timezone idMoment-objects using given locale and timezoneIllegalArgumentException - if resolving of pattern fails or the timezone cannot be loaded@Deprecated public static SimpleFormatter<Moment> ofMomentStyle(DisplayMode dateStyle, DisplayMode timeStyle, Locale locale, TZID tzid)
ofMomentStyle(FormatStyle, FormatStyle, Locale, TZID)Constructs a style-based formatter for global timestamp objects (moments).
dateStyle - format style for the date componenttimeStyle - format style for the time componentlocale - format localetzid - timezone idSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic static SimpleFormatter<Moment> ofMomentStyle(FormatStyle dateStyle, FormatStyle timeStyle, Locale locale, TZID tzid)
Constructs a style-based formatter for global timestamp objects (moments).
dateStyle - format style for the date componenttimeStyle - format style for the time componentlocale - format localetzid - timezone idSimpleFormatter-instanceIllegalStateException - if no localized format pattern can be retrievedpublic String print(T formattable)
TemporalFormatterPrints given chronological entity as formatted text.
print in interface TemporalFormatter<T>formattable - object to be formattedpublic T parse(CharSequence text) throws ParseException
TemporalFormatterInterpretes given text as chronological entity.
parse in interface TemporalFormatter<T>text - text to be parsedParseException - if the text is not parseablepublic T parse(CharSequence text, RawValues rawValues) throws ParseException
TemporalFormatterInterpretes given text as chronological entity and updates given raw values.
parse in interface TemporalFormatter<T>text - text to be parsedrawValues - holder for raw values (always as new instance)ParseException - if parsing does not workpublic TemporalFormatter<T> withTimezone(TZID tzid)
TemporalFormatterCreates 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.
withTimezone in interface TemporalFormatter<T>tzid - timezone idAttributes.TIMEZONE_IDpublic TemporalFormatter<T> withTimezone(String tzid)
TemporalFormatterEquivalent to withTimezone(Timezone.of(tzid).getID()).
withTimezone in interface TemporalFormatter<T>tzid - timezone idTemporalFormatter.withTimezone(TZID),
Attributes.TIMEZONE_IDpublic TemporalFormatter<T> with(Locale locale)
TemporalFormatterCreates 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.
with in interface TemporalFormatter<T>locale - new language and country configurationpublic TemporalFormatter<T> with(Leniency leniency)
TemporalFormatterSets the leniency mode.
By default any temporal formatter is smart.
with in interface TemporalFormatter<T>leniency - determines how strict the parser should beAttributes.LENIENCYpublic AttributeQuery getAttributes()
TemporalFormatterDetermines 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.
getAttributes in interface TemporalFormatter<T>Copyright © 2014–2021. All rights reserved.