public class

DateFormatter

extends Object
implements Formatter<T>
java.lang.Object
   ↳ org.springframework.format.datetime.DateFormatter

Class Overview

A formatter for java.util.Date types. Allows the configuration of an explicit date pattern and locale.

See Also
  • SimpleDateFormat

Summary

Public Constructors
DateFormatter()
Create a new default DateFormatter.
DateFormatter(String pattern)
Create a new DateFormatter for the given date pattern.
Public Methods
Date parse(String text, Locale locale)
Parse a text String to produce a T.
String print(Date date, Locale locale)
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 setTimeZone(TimeZone timeZone)
Set the TimeZone to normalize the date values into, if any.
Protected Methods
DateFormat getDateFormat(Locale locale)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.format.Parser
From interface org.springframework.format.Printer

Public Constructors

public DateFormatter ()

Create a new default DateFormatter.

public DateFormatter (String pattern)

Create a new DateFormatter for the given date pattern.

Public Methods

public Date parse (String text, Locale locale)

Parse a text String to produce a T.

Parameters
text the text string
locale the current user locale
Returns
  • an instance of T

public String print (Date date, Locale locale)

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.

public void setPattern (String pattern)

Set the pattern to use to format date values.

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

public void setStyle (int style)

Set the style to use to format date values.

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

public void setTimeZone (TimeZone timeZone)

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

Protected Methods

protected DateFormat getDateFormat (Locale locale)