DateFormatter (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.format.datetime

## Class DateFormatter

- java.lang.Object
- - org.springframework.format.datetime.DateFormatter

- All Implemented Interfaces:
    Formatter<Date>, Parser<Date>, Printer<Date>

      public class DateFormatter
      extends Object
      implements Formatter<Date>

  A formatter for `Date` types. Allows the configuration of an explicit date pattern and locale.
  Since:
    3.0
  Author:
    Keith Donald, Juergen Hoeller, Phillip Webb
  See Also:
    `SimpleDateFormat`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DateFormatter()` Create a new default DateFormatter.
    `DateFormatter(String pattern)` Create a new DateFormatter for the given date pattern.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected DateFormat` | `getDateFormat(Locale locale)`
    `Date` | `parse(String text, Locale locale)` Parse a text String to produce a T.
    `String` | `print(Date date, Locale locale)` Print the object of type T for display.
    `void` | `setIso(DateTimeFormat.ISO iso)` Set the ISO format used for this date.
    `void` | `setLenient(boolean lenient)` Specify whether or not parsing is to be lenient.
    `void` | `setPattern(String pattern)` Set the pattern to use to format date values.
    `void` | `setStyle(int style)` Set the style to use to format date values.
    `void` | `setStylePattern(String stylePattern)` Set the two character to use to format date values.
    `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 Detail

    - #### DateFormatter

          public DateFormatter()

      Create a new default DateFormatter.

    - #### DateFormatter

          public DateFormatter(String pattern)

      Create a new DateFormatter for the given date pattern.

  - ### Method Detail

    - #### setPattern

          public void setPattern(String pattern)

      Set the pattern to use to format date values.

      If not specified, DateFormat's default style will be used.

    - #### setStyle

          public void setStyle(int style)

      Set the style to use to format date values.

      If not specified, DateFormat's default style will be used.

      See Also:
        `DateFormat.DEFAULT`, `DateFormat.SHORT`, `DateFormat.MEDIUM`, `DateFormat.LONG`, `DateFormat.FULL`

    - #### setStylePattern

          public void setStylePattern(String stylePattern)

      Set the two character to use to format date values. The first character 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.
      Parameters:
        `stylePattern` - two characters from the set {"S", "M", "L", "F", "-"}
      Since:
        3.2

    - #### setIso

          public void setIso(DateTimeFormat.ISO iso)

      Set the ISO format used for this date.
      Parameters:
        `iso` - the `DateTimeFormat.ISO` format
      Since:
        3.2

    - #### setTimeZone

          public void setTimeZone(TimeZone timeZone)

      Set the TimeZone to 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

          public String print(Date date,
                     Locale locale)

      Description copied from interface: `Printer`
      Print the object of type T for display.
      Specified by:
        `print` in interface `Printer<Date>`
      Parameters:
        `date` - the instance to print
        `locale` - the current user locale
      Returns:
        the printed text string

    - #### parse

          public Date parse(String text,
                   Locale locale)
                     throws ParseException

      Description copied from interface: `Parser`
      Parse a text String to produce a T.
      Specified by:
        `parse` in 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

          protected DateFormat getDateFormat(Locale locale)