类 DateFormatter
java.lang.Object
cn.taketoday.format.datetime.DateFormatter
A formatter for
Date types.
Supports the configuration of an explicit date time pattern, timezone, locale, and fallback date time patterns for lenient parsing.
- 从以下版本开始:
- 4.0
- 作者:
- Keith Donald, Juergen Hoeller, Phillip Webb, Sam Brannen
- 另请参阅:
-
构造器概要
构造器构造器说明Create a new defaultDateFormatter.DateFormatter(String pattern) Create a newDateFormatterfor the given date time pattern. -
方法概要
修饰符和类型方法说明protected 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 or not 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.
-
构造器详细资料
-
DateFormatter
public DateFormatter()Create a new defaultDateFormatter. -
DateFormatter
Create a newDateFormatterfor the given date time pattern.
-
-
方法详细资料
-
setSource
Set 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.- 参数:
source- the source of the configuration
-
setPattern
Set the pattern to use to format date values.If not specified, DateFormat's default style will be used.
-
setFallbackPatterns
Set additional patterns to use as a fallback in case parsing fails for the configured pattern, ISO format, style, or style pattern.- 参数:
fallbackPatterns- the fallback parsing patterns- 另请参阅:
-
setIso
Set the ISO format to use to format date values.- 参数:
iso- theDateTimeFormat.ISOformat
-
setStyle
public void setStyle(int style) Set theDateFormatstyle to use to format date values.If not specified, DateFormat's default style will be used.
-
setStylePattern
Set 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
- 参数:
stylePattern- two characters from the set {"S", "M", "L", "F", "-"}
-
setTimeZone
Set theTimeZoneto normalize the date values into, if any. -
setLenient
public void setLenient(boolean lenient) Specify whether or not parsing is to be lenient. Default is false.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
从接口复制的说明:PrinterPrint the object of type T for display. -
parse
从接口复制的说明:ParserParse a text String to produce a T.- 指定者:
parse在接口中Parser<Date>- 参数:
text- the text stringlocale- the current user locale- 返回:
- an instance of T
- 抛出:
ParseException- when a parse exception occurs in a java.text parsing library
-
getDateFormat
-