Top Description Fields Constructors Methods
org.apache.commons.text.lookup

pack-priv final Class DateStringLookup

extends AbstractStringLookup
Class Inheritance
Imports
java.text.DateFormat, .SimpleDateFormat, java.util.Date, org.apache.commons.lang3.time.FastDateFormat, org.apache.commons.text.StringSubstitutor

Formats the current date with the format given in the key in a format compatible with java.text.SimpleDateFormat.

Using a StringLookup from the StringLookupFactory:

StringLookupFactory.INSTANCE.dateStringLookup().lookup("yyyy-MM-dd");

Using a StringSubstitutor:

StringSubstitutor.createInterpolator().replace("... ${date:yyyy-MM-dd} ..."));

The above examples convert "yyyy-MM-dd" to today's date, for example, "2019-08-04".

Public access is through StringLookupFactory.

See Also
StringLookupFactory

Field Summary

Modifier and TypeField and Description
pack-priv static final DateStringLookup
INSTANCE

Defines the singleton for this class.

Inherited from org.apache.commons.text.lookup.AbstractStringLookup:
SPLIT_CHSPLIT_STR

Constructor Summary

AccessConstructor and Description
private
DateStringLookup()

No need to build instances for now.

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

The formatted date.
formatDate
(final long
the date to format.
dateMillis
,
final String
the format string for SimpleDateFormat.
format
)

Formats the given date long with the given format.

public String

Returns:

The value of the environment variable.
lookup
(final String
the format to use. If null, the default DateFormat will be used.
key
)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Formats the current date with the format given in the key in a format compatible with java.text.SimpleDateFormat.

Inherited from org.apache.commons.text.lookup.AbstractStringLookup:
substringAftersubstringAftersubstringAfterLasttoLookupKeytoLookupKey

Field Detail

INSTANCEback to summary
pack-priv static final DateStringLookup INSTANCE

Defines the singleton for this class.

Constructor Detail

DateStringLookupback to summary
private DateStringLookup()

No need to build instances for now.

Method Detail

formatDateback to summary
private String formatDate(final long dateMillis, final String format)

Formats the given date long with the given format.

Parameters
dateMillis:long

the date to format.

format:String

the format string for SimpleDateFormat.

Returns:String

The formatted date.

lookupback to summary
public String lookup(final String key)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Formats the current date with the format given in the key in a format compatible with java.text.SimpleDateFormat.

Parameters
key:String

the format to use. If null, the default DateFormat will be used.

Returns:String

The value of the environment variable.

Annotations
@Override