Supports formatting by style pattern, ISO date time pattern, or custom format pattern string.
Can be applied to java., java., Long (for
millisecond timestamps) as well as JSR-310 java.time value types.
For style-based formatting, set the style attribute to the desired style pattern code.
The first character of the code is the date style, and the second character is the time style.
Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full.
The date or time may be omitted by specifying the style character '-' — for example,
'M-' specifies a medium format for the date with no time.
For ISO-based formatting, set the iso attribute to the desired ISO format,
such as ISO#DATE.
For custom formatting, set the pattern attribute to a date time pattern, such as
"yyyy/MM/dd hh:mm:ss a".
Each attribute is mutually exclusive, so only set one attribute per annotation instance (the one most convenient for your formatting needs).
iso attribute is specified, it takes precedence over the style attribute.Whenever the style or pattern attribute is used, the
default time zone of the JVM will
be used when formatting java. values. Whenever the iso
attribute is used when formatting java. values, UTC
will be used as the time zone. The same time zone will be applied to any
fallback patterns as well. In order to enforce
consistent use of UTC as the time zone, you can bootstrap the JVM with
-Duser.timezone=UTC.
java.time.format.DateTimeFormatter
| Modifier and Type | Class and Description |
|---|---|
| public static enum | DateTimeFormat.
Common ISO date time format patterns. |
| Modifier and Type | Method and Description |
|---|---|
| public String[] | fallbackPatterns()
The set of custom patterns to use as a fallback in case parsing fails for
the primary |
| public DateTimeFormat. | |
| public String | |
| public String |
| fallbackPatterns | back to summary |
|---|---|
| public String[] fallbackPatterns() The set of custom patterns to use as a fallback in case parsing fails for
the primary For example, if you wish to use the ISO date format for parsing and printing but allow for lenient parsing of user input for various date formats, you could configure something similar to the following.
@DateTimeFormat(iso = ISO.DATE, fallbackPatterns = { "M/d/yy", "dd.MM.yyyy" })
Fallback patterns are only used for parsing. They are not used for
printing the value as a String. The primary Fallback patterns are not supported for Joda-Time value types.
| |
| iso | back to summary |
|---|---|
| public DateTimeFormat. The ISO pattern to use to format the field or method parameter. Supported ISO patterns are defined in the Defaults to
| |
| pattern | back to summary |
|---|---|
| public String pattern() The custom pattern to use to format the field or method parameter. Defaults to empty String, indicating no custom pattern String has been specified. Set this attribute when you wish to format your field or method parameter in accordance with a custom date time pattern not represented by a style or ISO format. Note This pattern follows the original
| |
| style | back to summary |
|---|---|
| public String style() The style pattern to use to format the field or method parameter. Defaults to 'SS' for short date, short time. Set this attribute when you wish to format your field or method parameter in accordance with a common style other than the default style.
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final DateTimeFormat. | DATE
The most common ISO Date Format |
| public static final DateTimeFormat. | DATE_TIME
The most common ISO Date Time Format |
| public static final DateTimeFormat. | NONE
Indicates that no ISO-based format pattern should be applied. |
| public static final DateTimeFormat. | TIME
The most common ISO Time Format |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static DateTimeFormat. | |
| public static DateTimeFormat. |
| DATE | back to summary |
|---|---|
| public static final DateTimeFormat. The most common ISO Date Format | |
| DATE_TIME | back to summary |
|---|---|
| public static final DateTimeFormat. The most common ISO Date Time Format | |
| NONE | back to summary |
|---|---|
| public static final DateTimeFormat. Indicates that no ISO-based format pattern should be applied. | |
| TIME | back to summary |
|---|---|
| public static final DateTimeFormat. The most common ISO Time Format | |
| ISO | back to summary |
|---|---|
| private ISO() | |
| valueOf | back to summary |
|---|---|
| public static DateTimeFormat. | |
| values | back to summary |
|---|---|
| public static DateTimeFormat. | |