public class StdDateFormat
extends java.text.DateFormat
DateFormat
implementation used by standard Date
serializers and deserializers. 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.Modifier and Type | Field and Description |
---|---|
private java.util.Calendar |
_calendar
Lazily instantiated calendar used by this instance for serialization (
DateFormat.format(Date) ). |
private java.text.DateFormat |
_formatRFC1123 |
protected java.lang.Boolean |
_lenient
Explicit override for leniency, if specified.
|
protected java.util.Locale |
_locale |
protected java.util.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 (
HH:mm format) |
protected static java.lang.String[] |
ALL_FORMATS
For error messages we'll also need a list of all formats.
|
protected static java.util.Calendar |
CALENDAR
Blueprint "Calendar" instance for use during formatting.
|
protected static java.text.DateFormat |
DATE_FORMAT_ISO8601 |
protected static java.text.DateFormat |
DATE_FORMAT_RFC1123 |
static java.lang.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 java.lang.String |
DATE_FORMAT_STR_PLAIN
ISO-8601 with just the Date part, no time: needed for error messages
|
protected static java.lang.String |
DATE_FORMAT_STR_RFC1123
This constant defines the date format specified by
RFC 1123 / RFC 822.
|
protected static java.util.Locale |
DEFAULT_LOCALE |
protected static java.util.TimeZone |
DEFAULT_TIMEZONE
By default we use UTC for everything, with Jackson 2.7 and later
(2.6 and earlier relied on GMT)
|
static StdDateFormat |
instance
A singleton instance can be used for cloning purposes, as a blueprint of sorts.
|
protected static java.util.regex.Pattern |
PATTERN_ISO8601 |
protected static java.util.regex.Pattern |
PATTERN_PLAIN |
protected static java.lang.String |
PATTERN_PLAIN_STR |
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
Modifier | Constructor and Description |
---|---|
|
StdDateFormat() |
|
StdDateFormat(java.util.TimeZone tz,
java.util.Locale loc)
Deprecated.
|
protected |
StdDateFormat(java.util.TimeZone tz,
java.util.Locale loc,
java.lang.Boolean lenient) |
protected |
StdDateFormat(java.util.TimeZone tz,
java.util.Locale loc,
java.lang.Boolean lenient,
boolean formatTzOffsetWithColon) |
Modifier and Type | Method and Description |
---|---|
protected void |
_clearFormats() |
private static java.text.DateFormat |
_cloneFormat(java.text.DateFormat df,
java.lang.String format,
java.util.TimeZone tz,
java.util.Locale loc,
java.lang.Boolean lenient) |
protected static <T> boolean |
_equals(T value1,
T value2) |
protected void |
_format(java.util.TimeZone tz,
java.util.Locale loc,
java.util.Date date,
java.lang.StringBuffer buffer) |
protected java.util.Calendar |
_getCalendar(java.util.TimeZone tz) |
private static int |
_parse2D(java.lang.String str,
int index) |
private static int |
_parse4D(java.lang.String str,
int index) |
protected java.util.Date |
_parseAsISO8601(java.lang.String dateStr,
java.text.ParsePosition bogus) |
protected java.util.Date |
_parseDate(java.lang.String dateStr,
java.text.ParsePosition pos) |
private java.util.Date |
_parseDateFromLong(java.lang.String longStr,
java.text.ParsePosition pos) |
StdDateFormat |
clone() |
boolean |
equals(java.lang.Object o) |
java.lang.StringBuffer |
format(java.util.Date date,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition fieldPosition) |
static java.util.TimeZone |
getDefaultTimeZone() |
static java.text.DateFormat |
getISO8601Format(java.util.TimeZone tz,
java.util.Locale loc)
Deprecated.
Since 2.9
|
static java.text.DateFormat |
getRFC1123Format(java.util.TimeZone tz,
java.util.Locale loc)
Deprecated.
Since 2.9
|
java.util.TimeZone |
getTimeZone() |
int |
hashCode() |
boolean |
isColonIncludedInTimeZone()
Accessor for checking whether this instance would include colon
within timezone serialization or not: if {code true}, timezone offset
is serialized like
-06:00 ; if {code false} as -0600 . |
boolean |
isLenient() |
protected boolean |
looksLikeISO8601(java.lang.String dateStr)
Helper method used to figure out if input looks like valid
ISO-8601 string.
|
private static void |
pad2(java.lang.StringBuffer buffer,
int value) |
private static void |
pad3(java.lang.StringBuffer buffer,
int value) |
private static void |
pad4(java.lang.StringBuffer buffer,
int value) |
java.util.Date |
parse(java.lang.String dateStr) |
java.util.Date |
parse(java.lang.String dateStr,
java.text.ParsePosition pos) |
protected java.util.Date |
parseAsISO8601(java.lang.String dateStr,
java.text.ParsePosition pos) |
protected java.util.Date |
parseAsRFC1123(java.lang.String dateStr,
java.text.ParsePosition pos) |
void |
setLenient(boolean enabled)
Need to override since we need to keep track of leniency locally,
and not via underlying
Calendar instance like base class
does. |
void |
setTimeZone(java.util.TimeZone tz) |
java.lang.String |
toPattern() |
java.lang.String |
toString() |
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
+0500 or +05:00 ):
either this instance (if setting would not change), or newly
constructed instance with desired setting for colon inclusion. |
StdDateFormat |
withLenient(java.lang.Boolean b)
"Mutant factory" method that will return an instance that has specified leniency
setting: either
this instance (if setting would not change), or newly
constructed instance. |
StdDateFormat |
withLocale(java.util.Locale loc)
"Mutant factory" method that will return an instance that uses specified
Locale :
either this instance (if setting would not change), or newly
constructed instance with different Locale to use. |
StdDateFormat |
withTimeZone(java.util.TimeZone tz)
Method used for creating a new instance with specified timezone;
if no timezone specified, defaults to the default timezone (UTC).
|
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, parseObject, setCalendar, setNumberFormat
protected static final java.lang.String PATTERN_PLAIN_STR
protected static final java.util.regex.Pattern PATTERN_PLAIN
protected static final java.util.regex.Pattern PATTERN_ISO8601
public static final java.lang.String DATE_FORMAT_STR_ISO8601
protected static final java.lang.String DATE_FORMAT_STR_PLAIN
protected static final java.lang.String DATE_FORMAT_STR_RFC1123
protected static final java.lang.String[] ALL_FORMATS
protected static final java.util.TimeZone DEFAULT_TIMEZONE
protected static final java.util.Locale DEFAULT_LOCALE
protected static final java.text.DateFormat DATE_FORMAT_RFC1123
protected static final java.text.DateFormat DATE_FORMAT_ISO8601
public static final StdDateFormat instance
protected static final java.util.Calendar CALENDAR
protected transient java.util.TimeZone _timezone
protected final java.util.Locale _locale
protected java.lang.Boolean _lenient
Cannot be `final` because setLenient(boolean)
returns
`void`.
private transient java.util.Calendar _calendar
DateFormat.format(Date)
).private transient java.text.DateFormat _formatRFC1123
private boolean _tzSerializedWithColon
HH:mm
format)public StdDateFormat()
@Deprecated public StdDateFormat(java.util.TimeZone tz, java.util.Locale loc)
protected StdDateFormat(java.util.TimeZone tz, java.util.Locale loc, java.lang.Boolean lenient)
protected StdDateFormat(java.util.TimeZone tz, java.util.Locale loc, java.lang.Boolean lenient, boolean formatTzOffsetWithColon)
public static java.util.TimeZone getDefaultTimeZone()
public StdDateFormat withTimeZone(java.util.TimeZone tz)
public StdDateFormat withLocale(java.util.Locale loc)
Locale
:
either this
instance (if setting would not change), or newly
constructed instance with different Locale
to use.public StdDateFormat withLenient(java.lang.Boolean b)
this
instance (if setting would not change), or newly
constructed instance.public StdDateFormat withColonInTimeZone(boolean b)
+0500
or +05:00
):
either this
instance (if setting would not change), or newly
constructed instance with desired setting for colon inclusion.
NOTE: does NOT affect deserialization as colon is optional accepted but not required -- put another way, either serialization is accepted by this class.
public StdDateFormat clone()
clone
in class java.text.DateFormat
@Deprecated public static java.text.DateFormat getISO8601Format(java.util.TimeZone tz, java.util.Locale loc)
@Deprecated public static java.text.DateFormat getRFC1123Format(java.util.TimeZone tz, java.util.Locale loc)
public java.util.TimeZone getTimeZone()
getTimeZone
in class java.text.DateFormat
public void setTimeZone(java.util.TimeZone tz)
setTimeZone
in class java.text.DateFormat
public void setLenient(boolean enabled)
Calendar
instance like base class
does.setLenient
in class java.text.DateFormat
public boolean isLenient()
isLenient
in class java.text.DateFormat
public boolean isColonIncludedInTimeZone()
-06:00
; if {code false} as -0600
.
NOTE: only relevant for serialization (formatting), as deserialization (parsing) always accepts optional colon but does not require it, regardless of this setting.
true
if a colon is to be inserted between the hours and minutes
of the TZ offset when serializing as String; otherwise false
public java.util.Date parse(java.lang.String dateStr) throws java.text.ParseException
parse
in class java.text.DateFormat
java.text.ParseException
public java.util.Date parse(java.lang.String dateStr, java.text.ParsePosition pos)
parse
in class java.text.DateFormat
protected java.util.Date _parseDate(java.lang.String dateStr, java.text.ParsePosition pos) throws java.text.ParseException
java.text.ParseException
public java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)
format
in class java.text.DateFormat
protected void _format(java.util.TimeZone tz, java.util.Locale loc, java.util.Date date, java.lang.StringBuffer buffer)
private static void pad2(java.lang.StringBuffer buffer, int value)
private static void pad3(java.lang.StringBuffer buffer, int value)
private static void pad4(java.lang.StringBuffer buffer, int value)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toPattern()
public boolean equals(java.lang.Object o)
equals
in class java.text.DateFormat
public int hashCode()
hashCode
in class java.text.DateFormat
protected boolean looksLikeISO8601(java.lang.String dateStr)
private java.util.Date _parseDateFromLong(java.lang.String longStr, java.text.ParsePosition pos) throws java.text.ParseException
java.text.ParseException
protected java.util.Date parseAsISO8601(java.lang.String dateStr, java.text.ParsePosition pos) throws java.text.ParseException
java.text.ParseException
protected java.util.Date _parseAsISO8601(java.lang.String dateStr, java.text.ParsePosition bogus) throws java.lang.IllegalArgumentException, java.text.ParseException
java.lang.IllegalArgumentException
java.text.ParseException
private static int _parse4D(java.lang.String str, int index)
private static int _parse2D(java.lang.String str, int index)
protected java.util.Date parseAsRFC1123(java.lang.String dateStr, java.text.ParsePosition pos)
private static final java.text.DateFormat _cloneFormat(java.text.DateFormat df, java.lang.String format, java.util.TimeZone tz, java.util.Locale loc, java.lang.Boolean lenient)
protected void _clearFormats()
protected java.util.Calendar _getCalendar(java.util.TimeZone tz)
protected static <T> boolean _equals(T value1, T value2)