Top Description Fields Constructors Methods
org.springframework.format.datetime.standard

public Class DateTimeFormatterFactory

extends Object
Class Inheritance
Known Direct Subclasses
org.springframework.format.datetime.standard.DateTimeFormatterFactoryBean
Imports
java.time.format.DateTimeFormatter, .FormatStyle, java.util.TimeZone, org.springframework.format.annotation.DateTimeFormat.ISO, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

Factory that creates a JSR-310 java.time.format.DateTimeFormatter.

Formatters will be created using the defined pattern, ISO, and xxxStyle methods (considered in that order).

Authors
Juergen Hoeller, Phillip Webb, Sam Brannen
Since
4.0
See Also
createDateTimeFormatter(), createDateTimeFormatter(DateTimeFormatter), setPattern, setIso, setDateStyle, setTimeStyle, setDateTimeStyle, DateTimeFormatterFactoryBean

Field Summary

Modifier and TypeField and Description
private FormatStyle
private DateTimeFormat.ISO
private String
private FormatStyle
private TimeZone

Constructor Summary

AccessConstructor and Description
public
DateTimeFormatterFactory()

Create a new DateTimeFormatterFactory instance.

public
DateTimeFormatterFactory(String
the pattern to use to format date values
pattern
)

Create a new DateTimeFormatterFactory instance.

Method Summary

Modifier and TypeMethod and Description
private FormatStyle
public DateTimeFormatter

Returns:

a new date time formatter
createDateTimeFormatter
()

Create a new DateTimeFormatter using this factory.

public DateTimeFormatter

Returns:

a new date time formatter
createDateTimeFormatter
(DateTimeFormatter
the fall-back formatter to use when no specific factory properties have been set
fallbackFormatter
)

Create a new DateTimeFormatter using this factory.

public void
setDateStyle(FormatStyle dateStyle)

Set the style to use for date types.

public void
setDateTimeStyle(FormatStyle dateTimeStyle)

Set the style to use for date and time types.

public void
setIso(DateTimeFormat.ISO
the ISO format
iso
)

Set the ISO format used to format date values.

public void
setPattern(String
the format pattern
pattern
)

Set the pattern to use to format date values.

public void
setStylePattern(String
two characters from the set {"S", "M", "L", "F", "-"}
style
)

Set the two characters to use to format date values, in Joda-Time style.

public void
setTimeStyle(FormatStyle timeStyle)

Set the style to use for time types.

public void
setTimeZone(TimeZone
the time zone
timeZone
)

Set the TimeZone to normalize the date values into, if any.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dateStyleback to summary
private FormatStyle dateStyle
Annotations
@Nullable
isoback to summary
private DateTimeFormat.ISO iso
Annotations
@Nullable
patternback to summary
private String pattern
Annotations
@Nullable
timeStyleback to summary
private FormatStyle timeStyle
Annotations
@Nullable
timeZoneback to summary
private TimeZone timeZone
Annotations
@Nullable

Constructor Detail

DateTimeFormatterFactoryback to summary
public DateTimeFormatterFactory()

Create a new DateTimeFormatterFactory instance.

DateTimeFormatterFactoryback to summary
public DateTimeFormatterFactory(String pattern)

Create a new DateTimeFormatterFactory instance.

Parameters
pattern:String

the pattern to use to format date values

Method Detail

convertStyleCharacterback to summary
private FormatStyle convertStyleCharacter(char c)
Annotations
@Nullable
createDateTimeFormatterback to summary
public DateTimeFormatter createDateTimeFormatter()

Create a new DateTimeFormatter using this factory.

If no specific pattern or style has been defined, medium date time format will be used.

Returns:DateTimeFormatter

a new date time formatter

See Also
createDateTimeFormatter(DateTimeFormatter)
createDateTimeFormatterback to summary
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter)

Create a new DateTimeFormatter using this factory.

If no specific pattern or style has been defined, the supplied fallbackFormatter will be used.

Parameters
fallbackFormatter:DateTimeFormatter

the fall-back formatter to use when no specific factory properties have been set

Returns:DateTimeFormatter

a new date time formatter

setDateStyleback to summary
public void setDateStyle(FormatStyle dateStyle)

Set the style to use for date types.

setDateTimeStyleback to summary
public void setDateTimeStyle(FormatStyle dateTimeStyle)

Set the style to use for date and time types.

setIsoback to summary
public void setIso(DateTimeFormat.ISO iso)

Set the ISO format used to format date values.

Parameters
iso:DateTimeFormat.ISO

the ISO format

setPatternback to summary
public void setPattern(String pattern)

Set the pattern to use to format date values.

Parameters
pattern:String

the format pattern

setStylePatternback to summary
public void setStylePattern(String style)

Set the two characters to use to format date values, in Joda-Time style.

The first character is used for the date style; the second is for the time style. Supported characters are:

  • 'S' = Small
  • 'M' = Medium
  • 'L' = Long
  • 'F' = Full
  • '-' = Omitted

This method mimics the styles supported by Joda-Time. Note that JSR-310 natively favors java.time.format.FormatStyle as used for setDateStyle, setTimeStyle and setDateTimeStyle.

Parameters
style:String

two characters from the set {"S", "M", "L", "F", "-"}

setTimeStyleback to summary
public void setTimeStyle(FormatStyle timeStyle)

Set the style to use for time types.

setTimeZoneback to summary
public void setTimeZone(TimeZone timeZone)

Set the TimeZone to normalize the date values into, if any.

Parameters
timeZone:TimeZone

the time zone