public class DateFormatter extends java.lang.Object implements Formatter<java.util.Date>
Implements a basic formatter for Date objects. Accepts several known types and patterns, as well as arbitrary patterns. Under the covers uses DateFormat and SimpleDateFormat objects from the java.text package - it is advised that you become familiar with these classes before attempting to use custom patterns.
Format types affect the kind of information that is output. The supported format types are (values are not case sensitive):
Format strings affect the format of the selected output. One of the following known values may be supplied as the format string (named values are not case sensitive). If the value is not one of the following, it is passed to SimpleDateFormat as a pattern string.
Modifier and Type | Field and Description |
---|---|
protected static java.util.Map<java.lang.String,java.lang.Integer> |
namedPatterns
Maintains a map of named formats that can be used instead of patterns.
|
Constructor and Description |
---|
DateFormatter() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format(java.util.Date input)
Formats a Date as a String using the rules supplied when the formatter was built.
|
java.text.DateFormat |
getDateFormat()
Gets the date format that will format the date.
|
java.lang.String |
getFormatPattern()
Gets the named format string or date pattern to use to format the date.
|
java.lang.String |
getFormatType()
Gets the format type to be used to render dates as Strings.
|
java.util.Locale |
getLocale()
Gets the locale that output String should be in.
|
void |
init()
Constructs the DateFormat used for formatting, based on the values passed to the
various setter methods on the class.
|
void |
setDateFormat(java.text.DateFormat dateFormat)
Sets the date format that will format the date.
|
void |
setFormatPattern(java.lang.String formatPattern)
Sets the named format string or date pattern to use to format the date.
|
void |
setFormatType(java.lang.String formatType)
Sets the format type to be used to render dates as Strings.
|
void |
setLocale(java.util.Locale locale)
Sets the locale that output String should be in.
|
protected static final java.util.Map<java.lang.String,java.lang.Integer> namedPatterns
public void setFormatType(java.lang.String formatType)
setFormatType
in interface Formatter<java.util.Date>
public java.lang.String getFormatType()
public void setFormatPattern(java.lang.String formatPattern)
setFormatPattern
in interface Formatter<java.util.Date>
public java.lang.String getFormatPattern()
public void setLocale(java.util.Locale locale)
public java.util.Locale getLocale()
public void init()
init
in interface Formatter<java.util.Date>
StripesRuntimeException
- if the formatType is not one of 'date', 'time' or 'datetime'.public java.text.DateFormat getDateFormat()
public void setDateFormat(java.text.DateFormat dateFormat)
public java.lang.String format(java.util.Date input)
? Copyright 2005-2006, Stripes Development Team.