Date to a string as a date format, retaining precision down to milliseconds.
The formatted string is by default in UTC and English locale. You can provide a different Locale and
TimeZone that are used for serialization or null to use always the current TimeZone. Note, that
the default format uses 3-letter time zones that can be ambiguous and may cause wrong results at deserialization and
is localized since Java 6.
Using a Java 7 runtime or higher, the converter supports the datetime format defined by W3C (a subset of ISO 8601) at deserialization. Only the formats that also contain the time information.
Dates in a different era are using a special default pattern that contains the era itself.
| Modifier and Type | Field and Description |
|---|---|
| private final ThreadSafeSimpleDateFormat[] | |
| private static final String[] | |
| private static final String | |
| private static final String | |
| private final ThreadSafeSimpleDateFormat | |
| private final ThreadSafeSimpleDateFormat | |
| private static final long | |
| private static final TimeZone |
| Access | Constructor and Description |
|---|---|
| public | |
| public | DateConverter(final TimeZone
the TimeZone used to serialize the Date timeZone)Construct a DateConverter with standard formats, lenient set off and uses a given TimeZone for serialization. |
| public | DateConverter(final boolean
the lenient setting of lenient)SimpleDateFormat#setLenient(boolean)Construct a DateConverter with standard formats and using UTC. |
| public | DateConverter(final String
the default format defaultFormat, final String[] fallback formats acceptableFormats)Construct a DateConverter with lenient set off using UTC. |
| public | DateConverter(final String
the default format defaultFormat, final String[] fallback formats acceptableFormats, final TimeZone timeZone)Construct a DateConverter with a given TimeZone and lenient set off. |
| public | DateConverter(final String
the default format defaultFormat, final String[] fallback formats acceptableFormats, final boolean the lenient setting of lenient)SimpleDateFormat#setLenient(boolean)Construct a DateConverter. |
| public | DateConverter(final String
the default format defaultFormat, final String[] fallback formats acceptableFormats, final TimeZone the TimeZone used to serialize the Date timeZone, final boolean the lenient setting of lenient)SimpleDateFormat#setLenient(boolean)Construct a DateConverter. |
| public | DateConverter(final String
the default format for dates in a different era (may be
defaultEraFormat, final String null to drop era support)the default format defaultFormat, final String[] fallback formats acceptableFormats, final Locale locale to use for the format locale, final TimeZone the TimeZone used to serialize the Date timeZone, final boolean the lenient setting of lenient)SimpleDateFormat#setLenient(boolean)Construct a DateConverter. |
| acceptableFormats | back to summary |
|---|---|
| private final ThreadSafeSimpleDateFormat[] acceptableFormats | |
| DEFAULT_ACCEPTABLE_FORMATS | back to summary |
|---|---|
| private static final String[] DEFAULT_ACCEPTABLE_FORMATS | |
| DEFAULT_ERA_PATTERN | back to summary |
|---|---|
| private static final String DEFAULT_ERA_PATTERN | |
| DEFAULT_PATTERN | back to summary |
|---|---|
| private static final String DEFAULT_PATTERN | |
| defaultEraFormat | back to summary |
|---|---|
| private final ThreadSafeSimpleDateFormat defaultEraFormat | |
| defaultFormat | back to summary |
|---|---|
| private final ThreadSafeSimpleDateFormat defaultFormat | |
| ERA_START | back to summary |
|---|---|
| private static final long ERA_START | |
| UTC | back to summary |
|---|---|
| private static final TimeZone UTC | |
| DateConverter | back to summary |
|---|---|
| public DateConverter() Construct a DateConverter with standard formats and lenient set off. | |
| DateConverter | back to summary |
|---|---|
| public DateConverter(final TimeZone timeZone) Construct a DateConverter with standard formats, lenient set off and uses a given TimeZone for serialization.
| |
| DateConverter | back to summary |
|---|---|
| public DateConverter(final boolean lenient) Construct a DateConverter with standard formats and using UTC.
| |
| DateConverter | back to summary |
|---|---|
| public DateConverter(final String defaultFormat, final String[] acceptableFormats) Construct a DateConverter with lenient set off using UTC. | |
| DateConverter | back to summary |
|---|---|
| public DateConverter(final String defaultFormat, final String[] acceptableFormats, final TimeZone timeZone) Construct a DateConverter with a given TimeZone and lenient set off. | |
| DateConverter | back to summary |
|---|---|
| public DateConverter(final String defaultFormat, final String[] acceptableFormats, final boolean lenient) Construct a DateConverter.
| |
| DateConverter | back to summary |
|---|---|
| public DateConverter(final String defaultFormat, final String[] acceptableFormats, final TimeZone timeZone, final boolean lenient) Construct a DateConverter.
| |
| DateConverter | back to summary |
|---|---|
| public DateConverter(final String defaultEraFormat, final String defaultFormat, final String[] acceptableFormats, final Locale locale, final TimeZone timeZone, final boolean lenient) Construct a DateConverter.
| |
| appendErrors | back to summary |
|---|---|
| public void appendErrors(ErrorWriter errorWriter) Implements com. Doc from com. Append context information to an
| |
| canConvert | back to summary |
|---|---|
| public boolean canConvert(Class<T> type) Implements abstract com. Implements com. Doc from com. Determines whether the converter can marshall a particular type.
| |
| fromString | back to summary |
|---|---|
| public Object fromString(String str) Implements abstract com. Implements com. Doc from com. Unmarshals an Object from its single value representation. | |
| toString | back to summary |
|---|---|
| public String toString(Object obj) Overrides com. Implements com. Doc from com. Marshals an Object into a single value representation. | |