public class DateFormatter extends java.lang.Object implements Formatter<java.util.Date>
Date
types.
Allows the configuration of an explicit date pattern and locale.SimpleDateFormat
Modifier and Type | Field and Description |
---|---|
private DateTimeFormat.ISO |
iso |
private static java.util.Map<DateTimeFormat.ISO,java.lang.String> |
ISO_PATTERNS |
private boolean |
lenient |
private java.lang.String |
pattern |
private int |
style |
private java.lang.String |
stylePattern |
private java.util.TimeZone |
timeZone |
Constructor and Description |
---|
DateFormatter()
Create a new default DateFormatter.
|
DateFormatter(java.lang.String pattern)
Create a new DateFormatter for the given date pattern.
|
Modifier and Type | Method and Description |
---|---|
private java.text.DateFormat |
createDateFormat(java.util.Locale locale) |
protected java.text.DateFormat |
getDateFormat(java.util.Locale locale) |
private int |
getStylePatternForChar(int index) |
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 |
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(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 |
setStylePattern(java.lang.String stylePattern)
Set the two character to use to format date values.
|
void |
setTimeZone(java.util.TimeZone timeZone)
Set the TimeZone to normalize the date values into, if any.
|
private static final java.util.Map<DateTimeFormat.ISO,java.lang.String> ISO_PATTERNS
private java.lang.String pattern
private int style
private java.lang.String stylePattern
private DateTimeFormat.ISO iso
private java.util.TimeZone timeZone
private boolean lenient
public DateFormatter()
public DateFormatter(java.lang.String pattern)
public void setPattern(java.lang.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.
DateFormat.DEFAULT
,
DateFormat.SHORT
,
DateFormat.MEDIUM
,
DateFormat.LONG
,
DateFormat.FULL
public void setStylePattern(java.lang.String stylePattern)
stylePattern
- two characters from the set {"S", "M", "L", "F", "-"}public void setTimeZone(java.util.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 java.lang.String print(java.util.Date date, java.util.Locale locale)
Printer
public java.util.Date parse(java.lang.String text, java.util.Locale locale) throws java.text.ParseException
Parser
protected java.text.DateFormat getDateFormat(java.util.Locale locale)
private java.text.DateFormat createDateFormat(java.util.Locale locale)
private int getStylePatternForChar(int index)