org.springframework.ui.format.date
Class DateFormatter

java.lang.Object
  extended by org.springframework.ui.format.date.DateFormatter
All Implemented Interfaces:
Formatter<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
See Also:
SimpleDateFormat

Constructor Summary
DateFormatter()
          Create a new default DateFormatter.
DateFormatter(String pattern)
          Create a new DateFormatter for the given date pattern.
 
Method Summary
 String format(Date date, Locale locale)
          Format the object of type T for display.
protected  DateFormat getDateFormat(Locale locale)
           
 Date parse(String formatted, Locale locale)
          Parse an object from its formatted representation.
 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.
 
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

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.


format

public String format(Date date,
                     Locale locale)
Description copied from interface: Formatter
Format the object of type T for display.

Specified by:
format in interface Formatter<Date>
Parameters:
date - the object to format
locale - the user's locale
Returns:
the formatted display string

parse

public Date parse(String formatted,
                  Locale locale)
           throws ParseException
Description copied from interface: Formatter
Parse an object from its formatted representation.

Specified by:
parse in interface Formatter<Date>
Parameters:
formatted - a formatted representation
locale - the user's locale
Returns:
the parsed object
Throws:
ParseException - when a parse exception occurs

getDateFormat

protected DateFormat getDateFormat(Locale locale)