Date format manager.
Utility class to help manage consistent date formatting and parsing.
It may be advantageous to have multiple DateFormatManagers per
application. For example, one for handling the output (formatting) of
dates, and another one for handling the input (parsing) of dates.
| Method from org.apache.log4j.lf5.util.DateFormatManager Detail: |
public String format(Date date) {
return getDateFormatInstance().format(date);
}
|
public String format(Date date,
String pattern) {
DateFormat formatter = null;
formatter = getDateFormatInstance();
if (formatter instanceof SimpleDateFormat) {
formatter = (SimpleDateFormat) (formatter.clone());
((SimpleDateFormat) formatter).applyPattern(pattern);
}
return formatter.format(date);
}
|
public synchronized DateFormat getDateFormatInstance() {
return _dateFormat;
}
|
public synchronized Locale getLocale() {
if (_locale == null) {
return Locale.getDefault();
} else {
return _locale;
}
}
|
public synchronized String getOutputFormat() {
return _pattern;
} Deprecated! Use - getPattern().
This method has been deprecated in favour of getPattern(). |
public synchronized String getPattern() {
return _pattern;
}
|
public synchronized TimeZone getTimeZone() {
if (_timeZone == null) {
return TimeZone.getDefault();
} else {
return _timeZone;
}
}
|
public Date parse(String date) throws ParseException {
return getDateFormatInstance().parse(date);
}
|
public Date parse(String date,
String pattern) throws ParseException {
DateFormat formatter = null;
formatter = getDateFormatInstance();
if (formatter instanceof SimpleDateFormat) {
formatter = (SimpleDateFormat) (formatter.clone());
((SimpleDateFormat) formatter).applyPattern(pattern);
}
return formatter.parse(date);
}
|
public synchronized void setDateFormatInstance(DateFormat dateFormat) {
_dateFormat = dateFormat;
// No reconfiguration necessary!
}
|
public synchronized void setLocale(Locale locale) {
_locale = locale;
configure();
}
|
public synchronized void setOutputFormat(String pattern) {
_pattern = pattern;
configure();
} Deprecated! Use - setPattern().
This method has been deprecated in favour of setPattern(). |
public synchronized void setPattern(String pattern) {
_pattern = pattern;
configure();
}
Set the pattern. i.e. "EEEEE, MMMMM d, yyyy hh:mm aaa" |
public synchronized void setTimeZone(TimeZone timeZone) {
_timeZone = timeZone;
configure();
}
|