Package org.springframework.format.datetime.standard

# Class DateTimeFormatterFactory

java.lang.Object
org.springframework.format.datetime.standard.DateTimeFormatterFactory

Direct Known Subclasses:
  `DateTimeFormatterFactoryBean`

public class DateTimeFormatterFactory extends Object
Factory that creates a JSR-310 `DateTimeFormatter`.

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

Since:
  4.0
Author:
  Juergen Hoeller, Phillip Webb, Sam Brannen
See Also:
  - `createDateTimeFormatter()`
  - `createDateTimeFormatter(DateTimeFormatter)`
  - `setPattern(java.lang.String)`
  - `setIso(org.springframework.format.annotation.DateTimeFormat.ISO)`
  - `setDateStyle(java.time.format.FormatStyle)`
  - `setTimeStyle(java.time.format.FormatStyle)`
  - `setDateTimeStyle(java.time.format.FormatStyle)`
  - `DateTimeFormatterFactoryBean`

## Constructor Summary

Constructors
Constructor
Description
`DateTimeFormatterFactory()`
Create a new `DateTimeFormatterFactory` instance.
`DateTimeFormatterFactory(String pattern)`
Create a new `DateTimeFormatterFactory` instance.

## Method Summary

Modifier and Type
Method
Description
`DateTimeFormatter`
`createDateTimeFormatter()`
Create a new `DateTimeFormatter` using this factory.
`DateTimeFormatter`
`createDateTimeFormatter(DateTimeFormatter fallbackFormatter)`
Create a new `DateTimeFormatter` using this factory.
`void`
`setDateStyle(FormatStyle dateStyle)`
Set the style to use for date types.
`void`
`setDateTimeStyle(FormatStyle dateTimeStyle)`
Set the style to use for date and time types.
`void`
`setIso(DateTimeFormat.ISO iso)`
Set the ISO format used to format date values.
`void`
`setPattern(String pattern)`
Set the pattern to use to format date values.
`void`
`setStylePattern(String style)`
Set the two characters to use to format date values.
`void`
`setTimeStyle(FormatStyle timeStyle)`
Set the style to use for time types.
`void`
`setTimeZone(TimeZone timeZone)`
Set the `TimeZone` to normalize the date values into, if any.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### DateTimeFormatterFactory

public DateTimeFormatterFactory()
Create a new `DateTimeFormatterFactory` instance.

### DateTimeFormatterFactory

public DateTimeFormatterFactory(String pattern)
Create a new `DateTimeFormatterFactory` instance.

Parameters:
  `pattern` - the pattern to use to format date values

## Method Details

### setPattern

public void setPattern(String pattern)
Set the pattern to use to format date values.

Parameters:
  `pattern` - the format pattern

### setIso

public void setIso(DateTimeFormat.ISO iso)
Set the ISO format used to format date values.

Parameters:
  `iso` - the ISO format

### setDateStyle

public void setDateStyle(FormatStyle dateStyle)
Set the style to use for date types.

### setTimeStyle

public void setTimeStyle(FormatStyle timeStyle)
Set the style to use for time types.

### setDateTimeStyle

public void setDateTimeStyle(FormatStyle dateTimeStyle)
Set the style to use for date and time types.

### setStylePattern

public void setStylePattern(String style)
Set the two characters to use to format date values.

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

Note that JSR-310 natively favors `FormatStyle` as used for `setDateStyle(java.time.format.FormatStyle)`, `setTimeStyle(java.time.format.FormatStyle)`, and `setDateTimeStyle(java.time.format.FormatStyle)`.

Parameters:
  `style` - two characters from the set {"S", "M", "L", "F", "-"}

### setTimeZone

public void setTimeZone(TimeZone timeZone)
Set the `TimeZone` to normalize the date values into, if any.

Parameters:
  `timeZone` - the time zone

### createDateTimeFormatter

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:
  a new date time formatter
See Also:
  - `createDateTimeFormatter(DateTimeFormatter)`

### createDateTimeFormatter

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` - the fall-back formatter to use when no specific factory properties have been set
Returns:
  a new date time formatter