DateFormat implementation used by standard Date
serializers and deserializers to implement default behavior: does NOT
fully implement all aspects expected by DateFormat and as a consequence
SHOULD NOT to be used by code outside core Jackson databind functionality.
In particular, ParsePosition argument of parse(String, ParsePosition)
and format(Date, StringBuffer, FieldPosition) methods is fully ignored;
Jackson itself never calls these methods.
For serialization defaults to using
an ISO-8601 compliant format (format String "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
and for deserialization, both ISO-8601 and RFC-1123.
Note that `Z` in format String refers to ISO-8601 time offset notation which produces
values like "-08:00" -- that is, full minute/hour combo without colon, and not using `Z`
as alias for "+00:00".
Inclusion of colon as separator, as default setting, started in Jackson 2.11:
prior versions omitted it.
Note that it is possible to enable/disable use of colon in time offset by using method
withColonInTimeZone for creating new differently configured format instance,
and configuring ObjectMapper with it.
Todo
in Jackson 2.14 or later, should change behavior to fail if ParsePosition
is specified by caller (at least with non-0 offset).
| Modifier and Type | Field and Description |
|---|---|
| private transient Calendar | _calendar
Lazily instantiated calendar used by this instance for serialization ( |
| private transient DateFormat | |
| protected Boolean | _lenient
Explicit override for leniency, if specified. |
| protected final Locale | |
| protected transient TimeZone | _timezone
Caller may want to explicitly override timezone to use; if so, we will have non-null value here. |
| private boolean | _tzSerializedWithColon
Whether the TZ offset must be formatted with a colon between hours and minutes (
Defaults to |
| protected static final String[] | ALL_FORMATS
For error messages we'll also need a list of all formats. |
| protected static final Calendar | CALENDAR
Blueprint "Calendar" instance for use during formatting. |
| protected static final DateFormat | |
| public static final String | DATE_FORMAT_STR_ISO8601
Defines a commonly used date format that conforms to ISO-8601 date formatting standard, when it includes basic undecorated timezone definition. |
| protected static final String | DATE_FORMAT_STR_PLAIN
ISO-8601 with just the Date part, no time: needed for error messages |
| protected static final String | DATE_FORMAT_STR_RFC1123
This constant defines the date format specified by RFC 1123 / RFC 822. |
| protected static final Locale | |
| protected static final TimeZone | DEFAULT_TIMEZONE
By default we use UTC for everything, with Jackson 2.7 and later (2.6 and earlier relied on GMT) |
| public static final StdDateFormat | instance
A singleton instance can be used for cloning purposes, as a blueprint of sorts. |
| protected static final Pattern | |
| protected static final Pattern | |
| protected static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected void | |
| private static final DateFormat | |
| protected static <T> boolean | |
| protected void | |
| protected void | |
| protected Calendar | |
| private static int | |
| private static int | |
| protected Date | |
| protected Date | |
| private Date | |
| public StdDateFormat | |
| public boolean | equals(Object
object to be compared for equality o)Overrides java. Compares the specified object with this |
| public StringBuffer | format(Date
a Date to be formatted into a date-time string. date, StringBuffer the string buffer for the returning date-time string. toAppendTo, FieldPosition keeps track on the position of the field within
the returned string. For example, given a date-time text
fieldPosition)"1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition
is DateFormat#YEAR_FIELD, the begin index and end index of
fieldPosition will be set to 0 and 4, respectively.
Notice that if the same date-time field appears more than once in a
pattern, the fieldPosition will be set for the first occurrence
of that date-time field. For instance, formatting a Date to the
date-time string "1 PM PDT (Pacific Daylight Time)" using the
pattern "h a z (zzzz)" and the alignment field
DateFormat#TIMEZONE_FIELD, the begin index and end index of
fieldPosition will be set to 5 and 8, respectively, for the
first occurrence of the timezone pattern character 'z'.Implements abstract java. Formats a |
| public static TimeZone | |
| public static DateFormat | getISO8601Format(TimeZone tz, Locale loc)
Deprecated
Since 2.9
Method for getting a non-shared DateFormat instance that uses specified timezone and can handle simple ISO-8601 compliant date format. |
| public static DateFormat | getRFC1123Format(TimeZone tz, Locale loc)
Deprecated
Since 2.9
Method for getting a non-shared DateFormat instance that uses specific timezone and can handle RFC-1123 compliant date format. |
| public TimeZone | |
| public int | |
| public boolean | Returns: true if a colon is to be inserted between the hours and minutes
of the TZ offset when serializing as String; otherwise falseAccessor for checking whether this instance would include colon
within timezone serialization or not: if {code true}, timezone offset
is serialized like |
| public boolean | isLenient()
Overrides java. Tell whether date/time parsing is to be lenient. |
| protected boolean | looksLikeISO8601(String dateStr)
Helper method used to figure out if input looks like valid ISO-8601 string. |
| private static void | |
| private static void | |
| private static void | |
| public Date | parse(String
A dateStr)String whose beginning should be parsed.Overrides java. Parses text from the beginning of the given string to produce a date. |
| public Date | parse(String
The date/time string to be parsed dateStr, ParsePosition On input, the position at which to start parsing; on
output, the position at which parsing terminated, or the
start position if the parse failed. pos)Implements abstract java. Parse a date/time string according to the given parse position. |
| protected Date | |
| protected Date | |
| public void | setLenient(boolean
when enabled)true, parsing is lenientOverrides java. Need to override since we need to keep track of leniency locally,
and not via underlying |
| public void | setTimeZone(TimeZone
the given new time zone. tz)Overrides java. Sets the time zone for the calendar of this |
| public String | |
| public String | |
| public StdDateFormat | withColonInTimeZone(boolean b)
"Mutant factory" method that will return an instance that has specified
handling of colon when serializing timezone (timezone either written
like |
| public StdDateFormat | withLenient(Boolean b)
"Mutant factory" method that will return an instance that has specified leniency
setting: either |
| public StdDateFormat | withLocale(Locale loc)
"Mutant factory" method that will return an instance that uses specified
|
| public StdDateFormat | withTimeZone(TimeZone tz)
Method used for creating a new instance with specified timezone; if no timezone specified, defaults to the default timezone (UTC). |
| _calendar | back to summary |
|---|---|
| private transient Calendar _calendar Lazily instantiated calendar used by this instance for serialization (
| |
| _formatRFC1123 | back to summary |
|---|---|
| private transient DateFormat _formatRFC1123 | |
| _lenient | back to summary |
|---|---|
| protected Boolean _lenient Explicit override for leniency, if specified.
Cannot be `final` because
| |
| _locale | back to summary |
|---|---|
| protected final Locale _locale | |
| _timezone | back to summary |
|---|---|
| protected transient TimeZone _timezone Caller may want to explicitly override timezone to use; if so, we will have non-null value here. | |
| _tzSerializedWithColon | back to summary |
|---|---|
| private boolean _tzSerializedWithColon Whether the TZ offset must be formatted with a colon between hours and minutes (
Defaults to
| |
| ALL_FORMATS | back to summary |
|---|---|
| protected static final String[] ALL_FORMATS For error messages we'll also need a list of all formats. | |
| CALENDAR | back to summary |
|---|---|
| protected static final Calendar CALENDAR Blueprint "Calendar" instance for use during formatting. Cannot be used as is, due to thread-safety issues, but can be used for constructing actual instances more cheaply by cloning.
| |
| DATE_FORMAT_RFC1123 | back to summary |
|---|---|
| protected static final DateFormat DATE_FORMAT_RFC1123 | |
| DATE_FORMAT_STR_ISO8601 | back to summary |
|---|---|
| public static final String DATE_FORMAT_STR_ISO8601 Defines a commonly used date format that conforms to ISO-8601 date formatting standard, when it includes basic undecorated timezone definition. | |
| DATE_FORMAT_STR_PLAIN | back to summary |
|---|---|
| protected static final String DATE_FORMAT_STR_PLAIN ISO-8601 with just the Date part, no time: needed for error messages | |
| DATE_FORMAT_STR_RFC1123 | back to summary |
|---|---|
| protected static final String DATE_FORMAT_STR_RFC1123 This constant defines the date format specified by RFC 1123 / RFC 822. Used for parsing via `SimpleDateFormat` as well as error messages. | |
| DEFAULT_LOCALE | back to summary |
|---|---|
| protected static final Locale DEFAULT_LOCALE | |
| DEFAULT_TIMEZONE | back to summary |
|---|---|
| protected static final TimeZone DEFAULT_TIMEZONE By default we use UTC for everything, with Jackson 2.7 and later (2.6 and earlier relied on GMT) | |
| instance | back to summary |
|---|---|
| public static final StdDateFormat instance A singleton instance can be used for cloning purposes, as a blueprint of sorts. | |
| PATTERN_ISO8601 | back to summary |
|---|---|
| protected static final Pattern PATTERN_ISO8601 | |
| PATTERN_PLAIN | back to summary |
|---|---|
| protected static final Pattern PATTERN_PLAIN | |
| PATTERN_PLAIN_STR | back to summary |
|---|---|
| protected static final String PATTERN_PLAIN_STR | |
| StdDateFormat | back to summary |
|---|---|
| public StdDateFormat() | |
| StdDateFormat | back to summary |
|---|---|
| public StdDateFormat(TimeZone tz, Locale loc)
Deprecated
| |
| StdDateFormat | back to summary |
|---|---|
| protected StdDateFormat(TimeZone tz, Locale loc, Boolean lenient) | |
| StdDateFormat | back to summary |
|---|---|
protected StdDateFormat(TimeZone tz, Locale loc, Boolean lenient, boolean formatTzOffsetWithColon)
| |
| _clearFormats | back to summary |
|---|---|
| protected void _clearFormats() | |
| _cloneFormat | back to summary |
|---|---|
| private static final DateFormat _cloneFormat(DateFormat df, String format, TimeZone tz, Locale loc, Boolean lenient) | |
| _equals | back to summary |
|---|---|
| protected static <T> boolean _equals(T value1, T value2) | |
| _format | back to summary |
|---|---|
| protected void _format(TimeZone tz, Locale loc, Date date, StringBuffer buffer) | |
| _formatBCEYear | back to summary |
|---|---|
| protected void _formatBCEYear(StringBuffer buffer, int bceYearNoSign) | |
| _getCalendar | back to summary |
|---|---|
| protected Calendar _getCalendar(TimeZone tz) | |
| _parse2D | back to summary |
|---|---|
| private static int _parse2D(String str, int index) | |
| _parse4D | back to summary |
|---|---|
| private static int _parse4D(String str, int index) | |
| _parseAsISO8601 | back to summary |
|---|---|
| protected Date _parseAsISO8601(String dateStr, ParsePosition bogus) throws IllegalArgumentException, ParseException | |
| _parseDate | back to summary |
|---|---|
| protected Date _parseDate(String dateStr, ParsePosition pos) throws ParseException | |
| _parseDateFromLong | back to summary |
|---|---|
| private Date _parseDateFromLong(String longStr, ParsePosition pos) throws ParseException | |
| clone | back to summary |
|---|---|
| public StdDateFormat clone() Overrides java. Doc from java. Overrides Cloneable
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Compares the specified object with this | |
| format | back to summary |
|---|---|
| public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) Implements abstract java. Doc from java. Formats a
| |
| getDefaultTimeZone | back to summary |
|---|---|
| public static TimeZone getDefaultTimeZone() | |
| getISO8601Format | back to summary |
|---|---|
| public static DateFormat getISO8601Format(TimeZone tz, Locale loc)
Deprecated Since 2.9 Method for getting a non-shared DateFormat instance that uses specified timezone and can handle simple ISO-8601 compliant date format.
| |
| getRFC1123Format | back to summary |
|---|---|
| public static DateFormat getRFC1123Format(TimeZone tz, Locale loc)
Deprecated Since 2.9 Method for getting a non-shared DateFormat instance that uses specific timezone and can handle RFC-1123 compliant date format.
| |
| getTimeZone | back to summary |
|---|---|
| public TimeZone getTimeZone() Overrides java. Doc from java. Gets the time zone. This method is equivalent to the following call.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns the hash code for this
| |
| isColonIncludedInTimeZone | back to summary |
|---|---|
| public boolean isColonIncludedInTimeZone() Accessor for checking whether this instance would include colon
within timezone serialization or not: if {code true}, timezone offset
is serialized like Note only relevant for serialization (formatting), as deserialization (parsing) always accepts optional colon but does not require it, regardless of this setting.
| |
| isLenient | back to summary |
|---|---|
| public boolean isLenient() Overrides java. Doc from java. Tell whether date/time parsing is to be lenient. This method is equivalent to the following call.
| |
| looksLikeISO8601 | back to summary |
|---|---|
| protected boolean looksLikeISO8601(String dateStr) Helper method used to figure out if input looks like valid ISO-8601 string. | |
| pad2 | back to summary |
|---|---|
| private static void pad2(StringBuffer buffer, int value) | |
| pad3 | back to summary |
|---|---|
| private static void pad3(StringBuffer buffer, int value) | |
| pad4 | back to summary |
|---|---|
| private static void pad4(StringBuffer buffer, int value) | |
| parse | back to summary |
|---|---|
| public Date parse(String dateStr) throws ParseException Overrides java. Doc from java. Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.
See the
| |
| parse | back to summary |
|---|---|
| public Date parse(String dateStr, ParsePosition pos) Implements abstract java. Doc from java. Parse a date/time string according to the given parse position. For
example, if By default, parsing is lenient: If the input is not in the form used
by this object's format method but can still be parsed as a date, then
the parse succeeds. Clients may insist on strict adherence to the
format by calling This parsing operation uses the
| |
| parseAsISO8601 | back to summary |
|---|---|
| protected Date parseAsISO8601(String dateStr, ParsePosition pos) throws ParseException | |
| parseAsRFC1123 | back to summary |
|---|---|
| protected Date parseAsRFC1123(String dateStr, ParsePosition pos) | |
| setLenient | back to summary |
|---|---|
| public void setLenient(boolean enabled) Overrides java. Need to override since we need to keep track of leniency locally,
and not via underlying
| |
| setTimeZone | back to summary |
|---|---|
| public void setTimeZone(TimeZone tz) Overrides java. Doc from java. Sets the time zone for the calendar of this
The The | |
| toPattern | back to summary |
|---|---|
| public String toPattern() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| withColonInTimeZone | back to summary |
|---|---|
| public StdDateFormat withColonInTimeZone(boolean b) "Mutant factory" method that will return an instance that has specified
handling of colon when serializing timezone (timezone either written
like Note does NOT affect deserialization as colon is optional accepted but not required -- put another way, either serialization is accepted by this class.
| |
| withLenient | back to summary |
|---|---|
| public StdDateFormat withLenient(Boolean b) "Mutant factory" method that will return an instance that has specified leniency
setting: either
| |
| withLocale | back to summary |
|---|---|
| public StdDateFormat withLocale(Locale loc) "Mutant factory" method that will return an instance that uses specified
| |
| withTimeZone | back to summary |
|---|---|
| public StdDateFormat withTimeZone(TimeZone tz) Method used for creating a new instance with specified timezone; if no timezone specified, defaults to the default timezone (UTC). | |