public abstract class DateTimeFormat extends Object implements Format
createDateFormat(Locale).
For your convenience here is an example of a date time formatter from this package.
public final class StandardDateTime extends DateTimeFormat
{
private static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss";
@Override
protected DateFormat createDateFormat(Locale locale)
{
return new SimpleDateFormat(STANDARD_FORMAT, locale);
}
}
In order to use date time formatter one should create formatter instance - with default locale and time zone, optionally set new locale settings and / or time zone then execute format.
DateTimeFormat formatter = new FullDateTime();
formatter.setLocale(new Locale("ro"));
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String dateDisplay = formatter.format(new Date());
All date time formatters uses Java DateFormat for actual format. Since Java DateFormat is not synchronized
date time formatter instances are not thread safe. Anyway, inside a thread, formatter instances can be reused.
| Modifier and Type | Field and Description |
|---|---|
private DateFormat |
dateFormat
Date format instance in charge with actual formatting.
|
private Locale |
locale
Formatter locale settings.
|
private TimeZone |
timeZone
Formatter date time zone.
|
| Constructor and Description |
|---|
DateTimeFormat()
Construct date time formatter with default locale settings and time zone.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract DateFormat |
createDateFormat(Locale locale)
Factory method for date time formatter instance.
|
String |
format(Object date)
Format date object accordingly concrete date time formatter implementation.
|
Object |
parse(String value)
Parse date value and return
Date instance. |
void |
setLocale(Locale locale)
Set locale settings for this formatter instance.
|
void |
setTimeZone(TimeZone timeZone)
Set time zone for this date time formatter instance.
|
private Locale locale
private TimeZone timeZone
private DateFormat dateFormat
public DateTimeFormat()
protected abstract DateFormat createDateFormat(Locale locale)
locale - locale settings.public void setLocale(Locale locale)
format(Object).locale - locale settings.public void setTimeZone(TimeZone timeZone)
format(Object).timeZone - time zone.public String format(Object date)
createDateFormat(Locale),
Format.format(Object) on formatter instance.
Returns empty string if given date instance is null.
public Object parse(String value) throws ParseException
Date instance. Given value should encode a date instance
accordingly this formatter locale. Returns null if value argument is null or empty.parse in interface Formatvalue - date localized value.Date instance or null if value argument is null or empty.ParseException - if value argument is not a valid date accordingly this formatter locale.Copyright © 2018. All rights reserved.