public abstract class DateFormatSupplier extends ThreadLocal<DateFormat> implements Supplier<DateFormat>
ThreadLocal<DateFormat>
that will set the correct TimeZone when
the object is retrieved by get()
.
This exists as a way to get around thread safety issues in DateFormat
. This class also
contains helper methods that create some useful DateFormatSuppliers.
Instances of DateFormatSuppliers can be shared, but note that a DateFormat generated from it will
be shared by all classes within a Thread.
In general, the state of a retrieved DateFormat should not be changed, unless it makes sense to
only perform a state change within that Thread.Modifier and Type | Field and Description |
---|---|
static String |
HUMAN_READABLE_FORMAT |
Constructor and Description |
---|
DateFormatSupplier() |
DateFormatSupplier(TimeZone timeZone) |
Modifier and Type | Method and Description |
---|---|
static DateFormatSupplier |
createDefaultFormatSupplier()
Create a Supplier for
FormatterConfig.DefaultDateFormat s |
static DateFormatSupplier |
createSimpleFormatSupplier(String dateFormat)
Create a generator for SimpleDateFormats accepting a dateFormat
|
static DateFormatSupplier |
createSimpleFormatSupplier(String dateFormat,
TimeZone timeZone)
Create a generator for SimpleDateFormats accepting a dateFormat
|
DateFormat |
get()
Always sets the TimeZone, which is a fast operation
|
TimeZone |
getTimeZone() |
void |
setTimeZone(TimeZone timeZone) |
initialValue, remove, set, withInitial
public static final String HUMAN_READABLE_FORMAT
public DateFormatSupplier()
public DateFormatSupplier(TimeZone timeZone)
public TimeZone getTimeZone()
public void setTimeZone(TimeZone timeZone)
public DateFormat get()
get
in interface Supplier<DateFormat>
get
in class ThreadLocal<DateFormat>
public static DateFormatSupplier createDefaultFormatSupplier()
FormatterConfig.DefaultDateFormat
spublic static DateFormatSupplier createSimpleFormatSupplier(String dateFormat)
public static DateFormatSupplier createSimpleFormatSupplier(String dateFormat, TimeZone timeZone)
Copyright © 2011–2018 The Apache Software Foundation. All rights reserved.