Class StdDateFormat
- java.lang.Object
-
- java.text.Format
-
- java.text.DateFormat
-
- com.fasterxml.jackson.databind.util.StdDateFormat
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class StdDateFormat extends java.text.DateFormatDefaultDateFormatimplementation 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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Boolean_lenientExplicit override for leniency, if specified.protected java.util.Locale_localeprotected java.util.TimeZone_timezoneCaller may want to explicitly override timezone to use; if so, we will have non-null value here.protected static java.lang.String[]ALL_FORMATSFor error messages we'll also need a list of all formats.protected static java.util.CalendarCALENDARBlueprint "Calendar" instance for use during formatting.protected static java.text.DateFormatDATE_FORMAT_ISO8601protected static java.text.DateFormatDATE_FORMAT_RFC1123static java.lang.StringDATE_FORMAT_STR_ISO8601Defines a commonly used date format that conforms to ISO-8601 date formatting standard, when it includes basic undecorated timezone definition.protected static java.lang.StringDATE_FORMAT_STR_PLAINISO-8601 with just the Date part, no time: needed for error messagesprotected static java.lang.StringDATE_FORMAT_STR_RFC1123This constant defines the date format specified by RFC 1123 / RFC 822.protected static java.util.LocaleDEFAULT_LOCALEprotected static java.util.TimeZoneDEFAULT_TIMEZONEBy default we use UTC for everything, with Jackson 2.7 and later (2.6 and earlier relied on GMT)static StdDateFormatinstanceA singleton instance can be used for cloning purposes, as a blueprint of sorts.protected static java.util.regex.PatternPATTERN_ISO8601protected static java.util.regex.PatternPATTERN_PLAINprotected static java.lang.StringPATTERN_PLAIN_STR-
Fields inherited from class java.text.DateFormat
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
-
-
Constructor Summary
Constructors Modifier Constructor Description StdDateFormat()StdDateFormat(java.util.TimeZone tz, java.util.Locale loc)Deprecated.protectedStdDateFormat(java.util.TimeZone tz, java.util.Locale loc, java.lang.Boolean lenient)protectedStdDateFormat(java.util.TimeZone tz, java.util.Locale loc, java.lang.Boolean lenient, boolean formatTzOffsetWithColon)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void_clearFormats()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 void_formatBCEYear(java.lang.StringBuffer buffer, int bceYearNoSign)protected java.util.Calendar_getCalendar(java.util.TimeZone tz)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)StdDateFormatclone()booleanequals(java.lang.Object o)java.lang.StringBufferformat(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)static java.util.TimeZonegetDefaultTimeZone()static java.text.DateFormatgetISO8601Format(java.util.TimeZone tz, java.util.Locale loc)Deprecated.Since 2.9static java.text.DateFormatgetRFC1123Format(java.util.TimeZone tz, java.util.Locale loc)Deprecated.Since 2.9java.util.TimeZonegetTimeZone()inthashCode()booleanisColonIncludedInTimeZone()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.booleanisLenient()protected booleanlooksLikeISO8601(java.lang.String dateStr)Helper method used to figure out if input looks like valid ISO-8601 string.java.util.Dateparse(java.lang.String dateStr)java.util.Dateparse(java.lang.String dateStr, java.text.ParsePosition pos)protected java.util.DateparseAsISO8601(java.lang.String dateStr, java.text.ParsePosition pos)protected java.util.DateparseAsRFC1123(java.lang.String dateStr, java.text.ParsePosition pos)voidsetLenient(boolean enabled)Need to override since we need to keep track of leniency locally, and not via underlyingCalendarinstance like base class does.voidsetTimeZone(java.util.TimeZone tz)java.lang.StringtoPattern()java.lang.StringtoString()StdDateFormatwithColonInTimeZone(boolean b)"Mutant factory" method that will return an instance that has specified handling of colon when serializing timezone (timezone either written like+0500or+05:00): eitherthisinstance (if setting would not change), or newly constructed instance with desired setting for colon inclusion.StdDateFormatwithLenient(java.lang.Boolean b)"Mutant factory" method that will return an instance that has specified leniency setting: eitherthisinstance (if setting would not change), or newly constructed instance.StdDateFormatwithLocale(java.util.Locale loc)"Mutant factory" method that will return an instance that uses specifiedLocale: eitherthisinstance (if setting would not change), or newly constructed instance with differentLocaleto use.StdDateFormatwithTimeZone(java.util.TimeZone tz)Method used for creating a new instance with specified timezone; if no timezone specified, defaults to the default timezone (UTC).-
Methods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, parseObject, setCalendar, setNumberFormat
-
-
-
-
Field Detail
-
PATTERN_PLAIN_STR
protected static final java.lang.String PATTERN_PLAIN_STR
- See Also:
- Constant Field Values
-
PATTERN_PLAIN
protected static final java.util.regex.Pattern PATTERN_PLAIN
-
PATTERN_ISO8601
protected static final java.util.regex.Pattern PATTERN_ISO8601
-
DATE_FORMAT_STR_ISO8601
public static final 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.- See Also:
- Constant Field Values
-
DATE_FORMAT_STR_PLAIN
protected static final java.lang.String DATE_FORMAT_STR_PLAIN
ISO-8601 with just the Date part, no time: needed for error messages- See Also:
- Constant Field Values
-
DATE_FORMAT_STR_RFC1123
protected static final java.lang.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.- See Also:
- Constant Field Values
-
ALL_FORMATS
protected static final java.lang.String[] ALL_FORMATS
For error messages we'll also need a list of all formats.
-
DEFAULT_TIMEZONE
protected static final 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)
-
DEFAULT_LOCALE
protected static final java.util.Locale DEFAULT_LOCALE
-
DATE_FORMAT_RFC1123
protected static final java.text.DateFormat DATE_FORMAT_RFC1123
-
DATE_FORMAT_ISO8601
protected static final java.text.DateFormat DATE_FORMAT_ISO8601
-
instance
public static final StdDateFormat instance
A singleton instance can be used for cloning purposes, as a blueprint of sorts.
-
CALENDAR
protected static final java.util.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.- Since:
- 2.9.1
-
_timezone
protected transient java.util.TimeZone _timezone
Caller may want to explicitly override timezone to use; if so, we will have non-null value here.
-
_locale
protected final java.util.Locale _locale
-
_lenient
protected java.lang.Boolean _lenient
Explicit override for leniency, if specified.Cannot be `final` because
setLenient(boolean)returns `void`.- Since:
- 2.7
-
-
Constructor Detail
-
StdDateFormat
public StdDateFormat()
-
StdDateFormat
@Deprecated public StdDateFormat(java.util.TimeZone tz, java.util.Locale loc)Deprecated.
-
StdDateFormat
protected StdDateFormat(java.util.TimeZone tz, java.util.Locale loc, java.lang.Boolean lenient)
-
StdDateFormat
protected StdDateFormat(java.util.TimeZone tz, java.util.Locale loc, java.lang.Boolean lenient, boolean formatTzOffsetWithColon)- Since:
- 2.9.1
-
-
Method Detail
-
getDefaultTimeZone
public static java.util.TimeZone getDefaultTimeZone()
-
withTimeZone
public 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).
-
withLocale
public StdDateFormat withLocale(java.util.Locale loc)
"Mutant factory" method that will return an instance that uses specifiedLocale: eitherthisinstance (if setting would not change), or newly constructed instance with differentLocaleto use.
-
withLenient
public StdDateFormat withLenient(java.lang.Boolean b)
"Mutant factory" method that will return an instance that has specified leniency setting: eitherthisinstance (if setting would not change), or newly constructed instance.- Since:
- 2.9
-
withColonInTimeZone
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+0500or+05:00): eitherthisinstance (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.
- Since:
- 2.9.1
-
clone
public StdDateFormat clone()
- Overrides:
clonein classjava.text.DateFormat
-
getISO8601Format
@Deprecated public static java.text.DateFormat getISO8601Format(java.util.TimeZone tz, java.util.Locale loc)Deprecated.Since 2.9Method for getting a non-shared DateFormat instance that uses specified timezone and can handle simple ISO-8601 compliant date format.- Since:
- 2.4
-
getRFC1123Format
@Deprecated public static java.text.DateFormat getRFC1123Format(java.util.TimeZone tz, java.util.Locale loc)Deprecated.Since 2.9Method for getting a non-shared DateFormat instance that uses specific timezone and can handle RFC-1123 compliant date format.- Since:
- 2.4
-
getTimeZone
public java.util.TimeZone getTimeZone()
- Overrides:
getTimeZonein classjava.text.DateFormat
-
setTimeZone
public void setTimeZone(java.util.TimeZone tz)
- Overrides:
setTimeZonein classjava.text.DateFormat
-
setLenient
public void setLenient(boolean enabled)
Need to override since we need to keep track of leniency locally, and not via underlyingCalendarinstance like base class does.- Overrides:
setLenientin classjava.text.DateFormat
-
isLenient
public boolean isLenient()
- Overrides:
isLenientin classjava.text.DateFormat
-
isColonIncludedInTimeZone
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-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.
- Returns:
trueif a colon is to be inserted between the hours and minutes of the TZ offset when serializing as String; otherwisefalse- Since:
- 2.9.1
-
parse
public java.util.Date parse(java.lang.String dateStr) throws java.text.ParseException- Overrides:
parsein classjava.text.DateFormat- Throws:
java.text.ParseException
-
parse
public java.util.Date parse(java.lang.String dateStr, java.text.ParsePosition pos)- Specified by:
parsein classjava.text.DateFormat
-
_parseDate
protected java.util.Date _parseDate(java.lang.String dateStr, java.text.ParsePosition pos) throws java.text.ParseException- Throws:
java.text.ParseException
-
format
public java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition fieldPosition)- Specified by:
formatin classjava.text.DateFormat
-
_format
protected void _format(java.util.TimeZone tz, java.util.Locale loc, java.util.Date date, java.lang.StringBuffer buffer)
-
_formatBCEYear
protected void _formatBCEYear(java.lang.StringBuffer buffer, int bceYearNoSign)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toPattern
public java.lang.String toPattern()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.text.DateFormat
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.text.DateFormat
-
looksLikeISO8601
protected boolean looksLikeISO8601(java.lang.String dateStr)
Helper method used to figure out if input looks like valid ISO-8601 string.
-
parseAsISO8601
protected java.util.Date parseAsISO8601(java.lang.String dateStr, java.text.ParsePosition pos) throws java.text.ParseException- Throws:
java.text.ParseException
-
_parseAsISO8601
protected java.util.Date _parseAsISO8601(java.lang.String dateStr, java.text.ParsePosition bogus) throws java.lang.IllegalArgumentException, java.text.ParseException- Throws:
java.lang.IllegalArgumentExceptionjava.text.ParseException
-
parseAsRFC1123
protected java.util.Date parseAsRFC1123(java.lang.String dateStr, java.text.ParsePosition pos)
-
_clearFormats
protected void _clearFormats()
-
_getCalendar
protected java.util.Calendar _getCalendar(java.util.TimeZone tz)
-
_equals
protected static <T> boolean _equals(T value1, T value2)
-
-