public class DateFormatter extends Object implements Formatter<Date>
Date
types.
Allows the configuration of an explicit date pattern and locale.SimpleDateFormat
Constructor and Description |
---|
DateFormatter()
Create a new default DateFormatter.
|
DateFormatter(String pattern)
Create a new DateFormatter for the given date pattern.
|
Modifier and Type | Method and Description |
---|---|
protected DateFormat |
getDateFormat(Locale locale) |
Date |
parse(String text,
Locale locale)
Parse a text String to produce a T.
|
String |
print(Date date,
Locale locale)
Print the object of type T for display.
|
void |
setIso(DateTimeFormat.ISO iso)
Set the ISO format used for this date.
|
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 |
setStylePattern(String stylePattern)
Set the two character to use to format date values.
|
void |
setTimeZone(TimeZone timeZone)
Set the TimeZone to normalize the date values into, if any.
|
public DateFormatter()
public DateFormatter(String pattern)
public void setPattern(String pattern)
If not specified, DateFormat's default style will be used.
public void setIso(DateTimeFormat.ISO iso)
iso
- the DateTimeFormat.ISO
formatpublic void setStyle(int style)
If not specified, DateFormat's default style will be used.
public void setStylePattern(String stylePattern)
stylePattern
- two characters from the set {"S", "M", "L", "F", "-"}public void setTimeZone(TimeZone timeZone)
public void setLenient(boolean lenient)
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 String print(Date date, Locale locale)
Printer
public Date parse(String text, Locale locale) throws ParseException
Parser
parse
in interface Parser<Date>
text
- the text stringlocale
- the current user localeParseException
- when a parse exception occurs in a java.text parsing libraryprotected DateFormat getDateFormat(Locale locale)