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:
Function<String,,String> UnaryOperator<String>,StringLookup
Formats the current date with the format given in the key in a format compatible with
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:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final DateStringLookupDefines the singleton for this class.Fields inherited from class org.apache.commons.text.lookup.AbstractStringLookup
SPLIT_CH, SPLIT_STR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringformatDate(long dateMillis, String format) Formats the givendatelong with the givenformat.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, toLookupKeyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.text.lookup.StringLookup
apply
-
Field Details
-
INSTANCE
Defines the singleton for this class.
-
-
Constructor Details
-
DateStringLookup
private DateStringLookup()No need to build instances for now.
-
-
Method Details
-
formatDate
Formats the givendatelong with the givenformat.- Parameters:
dateMillis- the date to format.format- the format string forSimpleDateFormat.- Returns:
- The formatted date.
-
lookup
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.
-