Package org.apache.commons.text.lookup
Class DateStringLookup
- java.lang.Object
-
- org.apache.commons.text.lookup.AbstractStringLookup
-
- org.apache.commons.text.lookup.DateStringLookup
-
- All Implemented Interfaces:
StringLookup
final class DateStringLookup extends AbstractStringLookup
Formats the current date with the format given in the key in a format compatible withSimpleDateFormat.Using a
StringLookupfrom theStringLookupFactory: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".
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static DateStringLookupINSTANCEDefines the singleton for this class.-
Fields inherited from class org.apache.commons.text.lookup.AbstractStringLookup
SPLIT_CH, SPLIT_STR
-
-
Constructor Summary
Constructors Modifier Constructor Description privateDateStringLookup()No need to build instances for now.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringformatDate(long date, java.lang.String format)Formats the givendatelong with the givenformat.java.lang.Stringlookup(java.lang.String key)Formats the current date with the format given in the key in a format compatible withSimpleDateFormat.-
Methods inherited from class org.apache.commons.text.lookup.AbstractStringLookup
substringAfter, substringAfter, substringAfterLast, toLookupKey, toLookupKey
-
-
-
-
Field Detail
-
INSTANCE
static final DateStringLookup INSTANCE
Defines the singleton for this class.
-
-
Method Detail
-
formatDate
private java.lang.String formatDate(long date, java.lang.String format)Formats the givendatelong with the givenformat.- Parameters:
date- the date to formatformat- the format string forSimpleDateFormat.- Returns:
- The formatted date
-
lookup
public java.lang.String lookup(java.lang.String key)
Formats the current date with the format given in the key in a format compatible withSimpleDateFormat.- Parameters:
key- the format to use. If null, the defaultDateFormatwill be used.- Returns:
- The value of the environment variable.
-
-