Class DateFormatter
Date types.
 Supports the configuration of an explicit date time pattern, timezone, locale, and fallback date time patterns for lenient parsing.
Common ISO patterns for UTC instants are applied at millisecond precision.
 Note that InstantFormatter
 is recommended for flexible UTC parsing into a Instant instead.
- Since:
- 3.0
- Author:
- Keith Donald, Juergen Hoeller, Phillip Webb, Sam Brannen
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new defaultDateFormatter.DateFormatter(String pattern) Create a newDateFormatterfor the given date time pattern.
- 
Method SummaryModifier and TypeMethodDescriptionprotected DateFormatgetDateFormat(Locale locale) Parse a text String to produce a T.Print the object of type T for display.voidsetFallbackPatterns(String... fallbackPatterns) Set additional patterns to use as a fallback in case parsing fails for the configured pattern, ISO format, style, or style pattern.voidsetIso(DateTimeFormat.ISO iso) Set the ISO format to use to format date values.voidsetLenient(boolean lenient) Specify whether parsing is to be lenient.voidsetPattern(String pattern) Set the pattern to use to format date values.voidSet the source of the configuration for thisDateFormatter— for example, an instance of the@DateTimeFormatannotation if such an annotation was used to configure thisDateFormatter.voidsetStyle(int style) Set theDateFormatstyle to use to format date values.voidsetStylePattern(String stylePattern) Set the two characters to use to format date values.voidsetTimeZone(TimeZone timeZone) Set theTimeZoneto normalize the date values into, if any.
- 
Constructor Details- 
DateFormatterpublic DateFormatter()Create a new defaultDateFormatter.
- 
DateFormatterCreate a newDateFormatterfor the given date time pattern.
 
- 
- 
Method Details- 
setSourceSet the source of the configuration for thisDateFormatter— for example, an instance of the@DateTimeFormatannotation if such an annotation was used to configure thisDateFormatter.The supplied source object will only be used for descriptive purposes by invoking its toString()method — for example, when generating an exception message to provide further context.- Parameters:
- source- the source of the configuration
- Since:
- 5.3.5
 
- 
setPatternSet the pattern to use to format date values.If not specified, DateFormat's default style will be used. 
- 
setFallbackPatternsSet additional patterns to use as a fallback in case parsing fails for the configured pattern, ISO format, style, or style pattern.- Parameters:
- fallbackPatterns- the fallback parsing patterns
- Since:
- 5.3.5
- See Also:
 
- 
setIsoSet the ISO format to use to format date values.- Parameters:
- iso- the- DateTimeFormat.ISOformat
- Since:
- 3.2
 
- 
setStylepublic void setStyle(int style) Set theDateFormatstyle to use to format date values.If not specified, DateFormat's default style will be used. - See Also:
 
- 
setStylePatternSet the two characters to use to format date values.The first character is used for the date style; the second is used for the time style. Supported characters: - 'S' = Small
- 'M' = Medium
- 'L' = Long
- 'F' = Full
- '-' = Omitted
 - Parameters:
- stylePattern- two characters from the set {"S", "M", "L", "F", "-"}
- Since:
- 3.2
 
- 
setTimeZone
- 
setLenientpublic void setLenient(boolean lenient) Specify whether parsing is to be lenient. Default isfalse.With lenient parsing, the parser may allow inputs that do not precisely match the format. With strict parsing, inputs must match the format exactly. 
- 
print
- 
parseDescription copied from interface:ParserParse a text String to produce a T.- Specified by:
- parsein interface- Parser<Date>
- Parameters:
- text- the text string
- locale- the current user locale
- Returns:
- an instance of T
- Throws:
- ParseException- when a parse exception occurs in a java.text parsing library
 
- 
getDateFormat
 
-