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 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".

  • Field Details

    • INSTANCE

      static final DateStringLookup INSTANCE
      Defines the singleton for this class.
  • Constructor Details

    • DateStringLookup

      private DateStringLookup()
      No need to build instances for now.
  • Method Details

    • formatDate

      private String formatDate(long date, String format)
      Formats the given date long with the given format.
      Parameters:
      date - the date to format
      format - the format string for SimpleDateFormat.
      Returns:
      The formatted date
    • lookup

      public String lookup(String key)
      Formats the current date with the format given in the key in a format compatible with SimpleDateFormat.
      Parameters:
      key - the format to use. If null, the default DateFormat will be used.
      Returns:
      The value of the environment variable.