org.springframework.format.datetime
Class DateFormatter

java.lang.Object
  extended by org.springframework.format.datetime.DateFormatter
All Implemented Interfaces:
Formatter<java.util.Date>, Parser<java.util.Date>, Printer<java.util.Date>

public class DateFormatter
extends java.lang.Object
implements Formatter<java.util.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

Field Summary
private  boolean lenient
           
private  java.lang.String pattern
           
private  int style
           
private  java.util.TimeZone timeZone
           
 
Constructor Summary
DateFormatter()
          Create a new default DateFormatter.
DateFormatter(java.lang.String pattern)
          Create a new DateFormatter for the given date pattern.
 
Method Summary
protected  java.text.DateFormat getDateFormat(java.util.Locale locale)
           
 java.util.Date parse(java.lang.String text, java.util.Locale locale)
          Parse a text String to produce a T.
 java.lang.String print(java.util.Date date, java.util.Locale locale)
          Print the object of type T for display.
 void setLenient(boolean lenient)
          Specify whether or not parsing is to be lenient.
 void setPattern(java.lang.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(java.util.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
 

Field Detail

pattern

private java.lang.String pattern

style

private int style

timeZone

private java.util.TimeZone timeZone

lenient

private boolean lenient
Constructor Detail

DateFormatter

public DateFormatter()
Create a new default DateFormatter.


DateFormatter

public DateFormatter(java.lang.String pattern)
Create a new DateFormatter for the given date pattern.

Method Detail

setPattern

public void setPattern(java.lang.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(java.util.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 java.lang.String print(java.util.Date date,
                              java.util.Locale locale)
Description copied from interface: Printer
Print the object of type T for display.

Specified by:
print in interface Printer<java.util.Date>
Parameters:
date - the instance to print
locale - the current user locale
Returns:
the printed text string

parse

public java.util.Date parse(java.lang.String text,
                            java.util.Locale locale)
                     throws java.text.ParseException
Description copied from interface: Parser
Parse a text String to produce a T.

Specified by:
parse in interface Parser<java.util.Date>
Parameters:
text - the text string
locale - the current user locale
Returns:
an instance of T
Throws:
java.text.ParseException - when a parse exception occurs in a java.text parsing library

getDateFormat

protected java.text.DateFormat getDateFormat(java.util.Locale locale)