|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.format.DateFormatter
public class DateFormatter
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.
Field Summary | |
---|---|
protected static Map<String,Integer> |
namedPatterns
Maintains a map of named formats that can be used instead of patterns. |
Constructor Summary | |
---|---|
DateFormatter()
|
Method Summary | |
---|---|
String |
format(Date input)
Formats a Date as a String using the rules supplied when the formatter was built. |
DateFormat |
getDateFormat()
Gets the date format that will format the date. |
String |
getFormatPattern()
Gets the named format string or date pattern to use to format the date. |
String |
getFormatType()
Gets the format type to be used to render dates as Strings. |
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(DateFormat dateFormat)
Sets the date format that will format the date. |
void |
setFormatPattern(String formatPattern)
Sets the named format string or date pattern to use to format the date. |
void |
setFormatType(String formatType)
Sets the format type to be used to render dates as Strings. |
void |
setLocale(Locale locale)
Sets the locale that output String should be in. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final Map<String,Integer> namedPatterns
Constructor Detail |
---|
public DateFormatter()
Method Detail |
---|
public void setFormatType(String formatType)
setFormatType
in interface Formatter<Date>
public String getFormatType()
public void setFormatPattern(String formatPattern)
setFormatPattern
in interface Formatter<Date>
public String getFormatPattern()
public void setLocale(Locale locale)
setLocale
in interface Formatter<Date>
public Locale getLocale()
public void init()
init
in interface Formatter<Date>
StripesRuntimeException
- if the formatType is not one of 'date', 'time' or 'datetime'.public DateFormat getDateFormat()
public void setDateFormat(DateFormat dateFormat)
public String format(Date input)
format
in interface Formatter<Date>
input
- an object of a type that the formatter knows how to format
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |